如何制作带有两个图例的图表,其中一个图例是垂直的而另一个图例是水平的?
使用虹膜数据集,这是一个例子:
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))
Run Code Online (Sandbox Code Playgroud)
我希望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))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
165 次 |
| 最近记录: |