I have a ggplot with two legends, one for point colour and one for linetype.
我想仅扩展线型图例键的宽度。
legend.key.width
我可以使用来设置整体theme(legend.key.width = unit(5, "cm"))
,但这会增加两个图例的宽度。有没有办法只设置其中一个图例的宽度?
例子
iris$Group <- as.factor(rep(1:3, 50))
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_line(aes(linetype = Group))
Run Code Online (Sandbox Code Playgroud)
您可以按功能独立指定每种图例类型的选项guides()
:
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point(aes(colour = Species)) +
geom_line(aes(linetype = Group)) +
guides(linetype = guide_legend(keywidth = unit(5, 'cm')))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
647 次 |
最近记录: |