我正在尝试使用 ggplot 为仅以黑白打印的出版物制作带有堆叠条形的条形图。我每个条都有 6 个堆栈,因此使用 scale_fill_grey()
会使它看起来很奇怪并且难以阅读。有没有更好、更干净的方法来做到这一点?
这是我的数据:
dput(head(Russets))
structure(list(Variety = structure(c(4L, 4L, 4L, 4L, 4L, 5L), .Label = c("Burbank 2018",
"Norkotah 2018", "Silverton 2018", "Burbank 2019", "Norkotah 2019",
"Silverton 2019"), class = "factor"), Rate = c("1", "2", "3",
"4", "5", "1"), Hollow = c("67", "65", "64", "63", "67", "73"
), Double = c("42", "43", "42", "43", "48", "56"), Knob = c("351",
"391", "362", "348", "357", "371"), AllCWT.AC = c("AVGCWT.AC.0.4",
"AVGCWT.AC.0.4", "AVGCWT.AC.0.4", "AVGCWT.AC.0.4", "AVGCWT.AC.0.4",
"AVGCWT.AC.0.4"), ValueCWT.AC = c(224.92342125, 226.91992125,
226.967565, 237.4482825, 227.80791, 168.32446125), TuberSize = structure(c(1L,
1L, 1L, 1L, 1L, 1L), .Label = c("0-4 oz", "4-6 oz", "6-10 oz",
"10-13 oz", "13+ oz", "Culls"), class = "factor")), row.names = c(NA,
6L), class = "data.frame")
这是我当前的 ggplot:
RussetPlot <-ggplot(data=Russets,aes(x=Rate,y=ValueCWT.AC,group=interaction(TuberSize,Variety),fill=(TuberSize))) +
geom_col(position = "stack",inherit.aes = TRUE) +
facet_wrap(~Variety,nrow=2) +
scale_color_discrete(name = "Tuber Sizes", labels = c("0-4 oz", "4-6 oz", "6-10 oz", "10-13 oz", "13+ oz", "Culls"))
print(RussetPlot)
预先感谢您的任何建议!
最佳答案
更多手动选项(以@dc37的答案为基础):
使用scale_fill_manual()
ggplot(df, aes(x = variable, y = number, fill = fact))+
geom_col(color = "black)+
theme_bw()+
scale_fill_manual(values = c("grey10","grey30","grey50","grey70","grey80","grey90"))
数据
fact = rep(LETTERS[1:6],9)
number = rnorm(54)
variable = c(rep("a",18),rep("b",18),rep("c",18))
df = data.frame(fact,number, variable)
关于r - 制作带有多个堆叠部分的黑白 ggplot 条形图的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59430088/