【发布时间】:2012-10-19 18:11:06
【问题描述】:
这可以说是对这些问题的跟进:
Add legend to ggplot2 line plot
Add vline to existing plot and have it appear in ggplot2 legend?
我希望将几何图形添加到具有自己独立数据、比例和图例元素的绘图中。
我意识到这可能违反了图形原则的某些语法,但我经常发现自己想要图例中出现的垂直或水平线、单点、箭头等元素。
当其他几何映射中已经使用比例尺时,似乎会增加难度。
这里不是使用 iris 的漂亮示例:
p<-qplot(data=iris, x=Petal.Width,
y=Sepal.Width,
colour=Species,
shape=as.factor(round(Petal.Length)),
linetype=as.factor(round(Sepal.Length)),
geom=c("line", "point"))
p<-p+geom_vline(xintercept=0.75, aes(linetype="Setosa vs Versicolor"))
p<-p+geom_vline(xintercept=1.75, aes(linetype="Versicolor vs Virginica"))
print(p)
目前产生的,缺少 vline 的线型和关联图例。
【问题讨论】: