r - geom_beeswarm 和手动设置颜色 (scale_fill_manual)
问题描述
我正在使用 ggbeeswarm 包(带有geom_beeswarm()
)制作 beeswarm 图,并且我想根据因子变量中的因子水平手动填充颜色点。另外,我想设置点周围的颜色(白色)。
将颜色设置为fill = [FACTOR]
内部aes()
效果很好;这些点有不同的填充颜色,我可以像这样将点周围的线的颜色设置为白色geom_beeswarm(color = "white")
(参见下面的代码块#1)。但是当我想用 手动设置填充颜色时scale_fill_manual
,color = "white"
in 中的命令geom_beeswarm()
似乎会覆盖它(参见下面的代码块 #2)。
我怎样才能a)手动设置颜色和b)将我的点周围的线涂成白色?
(所有这些都适用于geom_point()
,但我geom_beeswarm()
更喜欢。)
这里有一些虚拟数据和代码来说明这一切:
# Provide minimal dataframe
x <- c(rep(c("A", "B"), 10))
y <- (rnorm(20, 2, 1))
z <- c(rep(c("Treatment", "Zero"), 10))
df <- data.frame(x, y, z)
# Draw beeswarm plot
library(ggbeeswarm)
# Works fine: (code chunk #1)
ggplot(df, aes(x, y, fill = z)) +
geom_beeswarm(color = "white",
pch = 21)
# Does not work fine: (code chunk #2)
ggplot(df, aes(x, y, fill = z)) +
geom_beeswarm(color = "white") +
scale_shape_manual(values=c(21, 21)) +
scale_fill_manual(values=c("#104E8B", "#72bcd4"))
解决方案
推荐阅读
- excel - 无法弄清楚如何索引、匹配和使用表中组合的 if 函数
- unit-testing - 在 Artos 中配置并行测试
- xpages - 如何使用 SSJS 从外部休息服务获取返回值
- javascript - 需要我发布到 npm 的包时遇到问题
- ip-camera - 在 ubuntu 的 OpenCV 中访问我的 ip wifi 摄像头,并且不会连接/流式传输
- jquery - 在 jQuery UI datepicker dateFormat 中允许使用破折号和斜杠
- google-apps-script - 适用于所有打开以适应屏幕以适应受保护工作表范围的用户的 google 工作表宏
- java - 如何根据使用 JSoup 选择的 JList 下载文件?
- r - 在 scale_x_discrete 中创建下标
- mysql - MySql:查找类型中每个产品子类型的最近日期