按组填充和图案的条形图 (GGPattern)
Barplot with fill and pattern by group (GGPattern)
我一直在尝试创建一个自定义条形图,我可以在其中更改每组的颜色和图案(条纹或无条纹)。
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"))
我尝试了以下创建下图的方法。
不过,我希望两个组都为白色,并且如果条件 == yes 的条中有黑色条纹,就像在 ggpattern 图中经常看到的那样。
使用 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"))
您在找这样的东西吗?
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))
我一直在尝试创建一个自定义条形图,我可以在其中更改每组的颜色和图案(条纹或无条纹)。
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"))
我尝试了以下创建下图的方法。
不过,我希望两个组都为白色,并且如果条件 == yes 的条中有黑色条纹,就像在 ggpattern 图中经常看到的那样。
使用 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"))
您在找这样的东西吗?
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))