[英]Adding scale_fill_grey changes the bar, but not line in ggplot2
我的数据如下:
counts <- structure(list(ECOST = c("0.08", "0.19", "0.07", "0.21", "0.06",
"0.20", "0.08", "0.19", "0.07", "0.21", "0.06", "0.20", "0.08",
"0.19", "0.07", "0.21", "0.06", "0.20", "0.08", "0.19", "0.07",
"0.21", "0.06", "0.20"), variable = structure(c(2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = c("treatment", "control"), class = "factor"),
percentage = c(0.714495882305909, 0.769654513612482, 0.803015075376884,
0.778858962374387, 0.824455825864277, 0.743992307222663,
0.731115523760302, 0.767143914637009, 0.775154121121069,
0.766219224551454, 0.800973964325206, 0.767750444842938,
0.281818181818182, 0.418181818181818, 0.5, 0.354545454545455,
0.5, 0.372727272727273, 0.329896907216495, 0.43298969072165,
0.536082474226804, 0.402061855670103, 0.597938144329897,
0.443298969072165), type = c("Contributions", "Contributions",
"Contributions", "Contributions", "Contributions", "Contributions",
"Contributions", "Contributions", "Contributions", "Contributions",
"Contributions", "Contributions", "Choices", "Choices", "Choices",
"Choices", "Choices", "Choices", "Choices", "Choices", "Choices",
"Choices", "Choices", "Choices"), group = c("Contributions control",
"Contributions control", "Contributions control", "Contributions control",
"Contributions control", "Contributions control", "Contributions treatment",
"Contributions treatment", "Contributions treatment", "Contributions treatment",
"Contributions treatment", "Contributions treatment", "Choices control",
"Choices control", "Choices control", "Choices control",
"Choices control", "Choices control", "Choices treatment",
"Choices treatment", "Choices treatment", "Choices treatment",
"Choices treatment", "Choices treatment")), row.names = c(NA,
-24L), class = c("data.table", "data.frame"))
library(ggplot2)
ggplot() +
geom_bar(data=filter(counts, group %in% c("Choices control", "Choices treatment")), aes(x = ECOST, y = percentage, fill=group), stat ="identity", position="dodge")+
geom_point(data=filter(counts, group %in% c("Contributions control", "Contributions treatment")),aes(x = ECOST, y = percentage,colour=group)) +
geom_line(data=filter(counts, group %in% c("Contributions control", "Contributions treatment")), aes(x = ECOST, y = percentage,colour=group, group=group)) +
theme_bw(base_size = 15)
创建这个 plot:
我想制作一个使用灰色阴影的版本。 但是,当我这样做时:
ggplot() +
geom_bar(data=filter(counts, group %in% c("Choices control", "Choices treatment")), aes(x = ECOST, y = percentage, fill=group), stat ="identity", position="dodge")+
geom_point(data=filter(counts, group %in% c("Contributions control", "Contributions treatment")),aes(x = ECOST, y = percentage,colour=group)) +
geom_line(data=filter(counts, group %in% c("Contributions control", "Contributions treatment")), aes(x = ECOST, y = percentage,colour=group, group=group)) +
theme_bw(base_size = 15) +
scale_fill_grey(start = 0.8, end = 0.5)
只有条改变,而不是线条。我如何改变线条?
添加scale_color_grey()
将使线条颜色变为灰色阴影,例如
ggplot() +
geom_bar(data=subset(counts, group %in% c("Choices control", "Choices treatment")), aes(x = ECOST, y = percentage, fill=group), stat ="identity", position="dodge")+
geom_point(data=subset(counts, group %in% c("Contributions control", "Contributions treatment")),aes(x = ECOST, y = percentage,colour=group)) +
geom_line(data=subset(counts, group %in% c("Contributions control", "Contributions treatment")), aes(x = ECOST, y = percentage,colour=group, group=group)) +
theme_bw(base_size = 15) +
scale_fill_grey(start = 0.8, end = 0.5)+
scale_color_grey()
scale_fill_grey()
将渲染框 plot、条形 plot、小提琴 plot 等,而scale_color_grey()
用于线条。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.