I have data as follows:
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)
Creating this plot:
I want to make a version which uses shade of grey. However, when I do:
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)
Only the bars change, and not the lines.. How do I change the lines as well?
Adding scale_color_grey()
will make line colours in grey shades like
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()
will render box plot, bar plot, violin plot, etc. in grey shades while scale_color_grey()
is used for lines and points.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.