ggarrange从图例中删除项目(ggplot2和ggpubr)

我正在尝试使组箱形图显示在网格布局中,并且我希望为侧面显示的每个组提供一个共同的图例。我已经对一个数据子集进行了此操作,这是代码示例

group.colors=c("V"= "#F8766D","W"= "#619CFF","X" ="#00BA38","Y"="#E69F00","Z"="#999999")

g1=ggplot(data=df[df$analyte=="BP3",],aes(x=analyte,y=concentration,fill=Lab_ID))+geom_boxplot(outlier.shape = NA)+geom_point(aes(group=Lab_ID),position=position_dodge(width=0.75),size=1.5,alpha=.9)+theme_bw()+theme(legend.position = "none")
g1=g1+scale_fill_manual(values=group.colors)+ylab("concentration (ng/mL)")+xlab("")

g2=ggplot(data=df[df$analyte=="BPA",alpha=.9)+theme_bw()+theme(legend.position = "none")
g2=g2+scale_fill_manual(values=group.colors)+ylab("concentration (ng/mL)")+xlab("")

f=ggarrange(g1,g2,nrow=1,ncol=2,common.legend=TRUE,legend="right")
annotate_figure(f,top= text_grob("Title",face = "bold",size = 16))

由于某些原因,当我在不同的分析物组上使用相同的代码时,图例并没有列出所有组,即使这些组在箱图中也是如此

我尝试在scale_fill_manual中包括限制,但它什么也没做

blackless 回答:ggarrange从图例中删除项目(ggplot2和ggpubr)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3148914.html

大家都在问