首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按组填充和模式的Barplot (GGPattern)

按组填充和模式的Barplot (GGPattern)
EN

Stack Overflow用户
提问于 2022-04-25 19:30:11
回答 1查看 941关注 0票数 2

我一直在尝试创建一个自定义条形图,在这里我可以更改每个组的颜色和图案(条纹或无条纹)。

代码语言:javascript
复制
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‘是我遇到的最常见的错误之一。

代码语言:javascript
复制
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")) 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-25 20:01:16

你在找这样的东西吗?

代码语言:javascript
复制
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))

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72004804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档