我一直在尝试创建一个自定义条形图,在这里我可以更改每个组的颜色和图案(条纹或无条纹)。
structure(list(Level= c(0.2, 0.3, 0.25, 0.35, 0.4, 0.5, 0.5, 0.6, 0.15, 0.35), Group= c("A", "A",
"B", "B", "C", "C", "D", "D",
"E", "E"), Condition = c("no", "yes", "no", "yes", "no", "yes", "no",
"yes", "no", "yes")), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))我尝试了下面的方法来创建下面的图表。

然而,I希望这两个组都是白色的,如果条件==是的条形图中有黑色条纹,就像as模式图中经常看到的那样。
使用ggpattern,我无法在seq.default(from,to,by)中找到可行的解决方案错误:无效的'(to - from)/by‘是我遇到的最常见的错误之一。
p<- ggplot(z, aes(fill=Condition, y=Level, x=Group, pattern = Condition)) +
geom_bar(position="dodge", stat="identity") +
ggpubr::theme_pubr() +
theme(legend.position = "top") +
theme( panel.background = element_rect(colour = "black", size=0.5)) +
labs(x = "Group", y = "Level")+
scale_y_continuous(breaks=seq(0, 0.8, 0.1))+
scale_fill_discrete(name = "", labels = c("No", "Yes")) 发布于 2022-04-25 20:01:16
你在找这样的东西吗?
ggplot(z, aes(fill=Condition, y=Level, x=Group, pattern = Condition,
pattern_type = Condition)) +
geom_bar_pattern(position="dodge", stat="identity", pattern_fill = "black",
fill = "white", colour = "black", pattern_spacing = 0.01,
pattern_frequency = 5, pattern_angle = 45) +
ggpubr::theme_pubr() +
theme(legend.position = "top") +
theme( panel.background = element_rect(colour = "black", size=0.5)) +
labs(x = "Group", y = "Level")+
scale_y_continuous(breaks=seq(0, 0.8, 0.1), limits = c(0, 0.8)) +
scale_pattern_manual(values=c('stripe', 'none')) +
scale_pattern_type_manual(values=c(NA, NA))

https://stackoverflow.com/questions/72004804
复制相似问题