在ggplot2中,如何选择在图例中出现哪个几何? [英] In ggplot2, how to choose which geom appears in legend?
问题描述
如何选择图例中出现哪个几何图形?
例如:
qplot(data = CO2,
x = Type,
y = uptake,
color = Plant,
shape = Treatment)+
geom_boxplot()
切换geoms的顺序有助于
qplot(data = CO2,
x = Type,
y =吸收,
color = Plant,
shape =治疗,
geom =boxplot)+
geom_point()
但我希望找到的图例是:
qplot(data = CO2,
x =类型,
y =吸收量,
颜色=工厂,
形状= Tr食物)
我需要提取一个图的图例并使用gridExtra之类的东西粘贴到另一个图上吗?
您可以通过将 show_guide = FALSE
添加到boxplot的图例 geom_boxplot()
调用。
qplot(data = CO2,
x =类型,
y =吸收,
color = Plant,
shape = Treatment)+
geom_boxplot(show_guide = FALSE)
如果你还没有绘制点(也就是只有boxplot,但想要用点符号而不是boxplot符号显示图例),那很难,尽管我认为可能。
Some geom obscure the key to other geoms in the legend (notably, boxplot)
How can I choose which geom appears in the legend?
Eg.:
qplot(data=CO2,
x=Type,
y=uptake,
colour=Plant,
shape=Treatment)+
geom_boxplot()
Switching the order of the geoms helps
qplot(data=CO2,
x=Type,
y=uptake,
colour=Plant,
shape=Treatment,
geom="boxplot")+
geom_point()
But I would like the legend found with:
qplot(data=CO2,
x=Type,
y=uptake,
colour=Plant,
shape=Treatment)
Do I need to extract the legend of one plot and paste it to the other using something like gridExtra?
You can suppress the legend for the boxplot by adding show_guide=FALSE
to the geom_boxplot()
call. You still get the legend from the points.
qplot(data=CO2,
x=Type,
y=uptake,
colour=Plant,
shape=Treatment)+
geom_boxplot(show_guide=FALSE)
If you were not already plotting points (that is, just had boxplot, but wanted the legend to be shown with points symbol rather than the boxplot symbol), that is harder, though I think possible.
这篇关于在ggplot2中,如何选择在图例中出现哪个几何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!