如何生成具有两个图例的图,其中一个图例是垂直的,另一个图例为水平的?
使用虹膜数据集,这里有一个例子:
ggplot(iris,aes(x=Sepal.Width,y=Petal.Width,color=Species,size=Sepal.Length))+
geom_point() +
scale_size_continuous(breaks=c(seq(from=5,to=7,by=0.4))) +
facet_wrap(~Species,ncol = 2) +
theme(legend.position=c(.7,.2))
我希望Species
的颜色图例保持垂直,但Sepal.Length
的图例在其下方保持水平。这可能吗?
注意:我知道贴面会使颜色图例变得不必要。我只是举个例子。
您可以使用guides
接口控制特定图例的功能。
ggplot(iris,aes(x=Sepal.Width,y=Petal.Width,color=Species,size=Sepal.Length))+
geom_point() +
scale_size_continuous(breaks=c(seq(from=5,to=7,by=0.4))) +
guides(size=guide_legend(direction='horizontal')) +
facet_wrap(~Species,ncol = 2) +
theme(legend.position=c(.7,.2))