r语言 - 添加模式到ggplot



我有这两个图,我想添加图案(或其他东西),这样颜色就不是唯一的区分因素。在情节中使用的任何模式都必须在图例中显示出来。我该怎么做呢?以下是我的示例数据和绘图代码。

Data <- data.frame(Label=c("BB","BB","BB","BB","WZ", "WZ","WZ", "WZ"), Direction=c("EB", "WB", "EB", "WB", "EB", "WB", "EB", "WB"), Delay=c(225, 137, 419, 265, 124, 234, 256, 256) )
Data$Label <- as.factor(Data$Label)
ggplot(Data,aes(x=Direction, y=(Delay), fill=Label))+
scale_fill_manual("legend", values = c("BB" = "#00BFCa", "WZ" = 
"#F8766D"))+
geom_text(aes(label=round(Delay)), 
position=position_dodge(width=0.9), vjust=-0.25) +
geom_bar(stat="identity",position="dodge") +   xlab("Travel 
Direction")+ ylab("Aggregated Delay (hours)") +
guides(fill=guide_legend(title=NULL)) + theme(plot.title = 
element_text(size=12) )
ggplot(Data, aes(x=Direction, y=Delay)) + geom_boxplot(aes(fill=Label), 
outlier.colour = 8, outlier.shape = 1) + 
scale_fill_manual("legend", values = c("BB" = "#00BFCa", "WZ" = 
"#F8766D")) +
xlab("Direction") + ylab("DElay") + ggtitle("By Direction") + 
guides(fill=guide_legend(title=NULL)) + theme(plot.title = 
element_text(size=12)) + theme(plot.title = element_text(hjust = 0.5)) 

我想这个链接可以帮助你:https://coolbutuseless.github.io/package/ggpattern/articles/geom-gallery-array.html#geom-map-pattern-

函数geom_bin2d_pattern()似乎是你需要的。

相关内容

  • 没有找到相关文章

最新更新