问题描述
我遇到了 ggpairs
中消失的图例问题。
我在下三角 ggpairs
图的顶部添加了一个图例,如下所示。
首先我创建了一个没有图例的 ggpairs
图,然后我去掉了我想要的图例和临时图,并用 ggpairs
将它放置在 putPlot
图中。在我尝试修改使图例消失的主题之前,它运行良好。
# 1 produce graph without legend
library(GGally)
library(ggplot2)
plotwithoutlegend <-ggpairs(
iris,columns=1:4,switch="both",upper="blank",mapping=aes(color = Species,shape= Species,fill=Species,alpha=0.5)
)
#2 grab the legend from a graph with the legend I want (without alpha).
auxplot <- ggplot(iris,aes(x=Petal.Length,y=Petal.Width,color=Species,shape=Species,fill=Species)) + geom_point()
mylegend <- grab_legend(auxplot)
# 3 place the legend in the ggpairs grid with putPlot
graph1 <- putPlot(plotwithoutlegend,mylegend,3,4)
show(graph1)
这会生成一个在所需位置带有图例的图表。
ggpairs
更改主题前的图例图:
但是,如果我更改主题的某些方面,图例就会消失。
graph2 <- graph1 +theme(strip.background =element_blank(),strip.placement = "outside")
show(graph2)
更改主题后图例消失:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)