r - ggplot中的因子颜色和连续变量
问题描述
我正在尝试使用颜色来突出因子水平之间和内部的差异。例如,使用这些可重现的数据:
set.seed(123)
dat <- data.frame(
Factor = sample(c("AAA", "BBB", "CCC"), 50, replace = T),
ColorValue = sample(1:4, 50 , replace = T),
x = sample(1:50, 50, replace =T),
y = sample(1:50, 50, replace =T))
head(dat)
Factor ColorValue x y
1 AAA 1 30 43
2 CCC 2 17 25
3 BBB 4 25 20
4 CCC 1 48 13
5 CCC 3 25 6
6 AAA 1 45 20
我想为每个因素使用不同的颜色。然后,在每个因素中,我试图将ColorValue
其用作连续着色变量来显示强度。
在下图中,每个方面将具有反映 的不同深浅的红色、绿色和蓝色ColorValue
,理想情况下,所有三个因子水平都具有单个强度(即 ColorValue)图例。
ggplot(dat, aes(x = x, y = y, color = Factor)) +
geom_point(size = 3) +
facet_wrap(~Factor) +
theme_bw()
解决方案
ggplot(dat, aes(x = x, y = y, color = Factor, alpha = ColorValue)) +
geom_point(size = 3) +
facet_wrap(~Factor) +
theme_bw()
推荐阅读
- x86 - 在完全虚拟化环境中,来宾操作系统系统调用会发生什么?
- jenkins - Jenkins 作业未能执行日志轮换消息
- php - 如何在 docker 容器中启用 php-fpm 的访问日志?
- vbscript - WshShell.Run 在命令行参数中带有空格
- java - 当按下 Enter 时,Java 中的循环不会中断,当条件是 DataInputStream.isAvailable() == 0 并且应用程序使用 telnet 运行时
- javascript - 如何将句子而不是单个单词发送到 API 并让它们发回
- c# - 通过 FuelSDK 从 C# 调用 Marketing Cloud API
- java - 无法使用 Java 使用 JAXB 读取 XML 文件的子节点中的内容
- javascript - Discord.JS 如何从旧消息中获取表情
- laravel - Laravel - 如何在不同域之间使用 Auth::check 或 Auth::user?