【发布时间】:2010-12-19 17:50:56
【问题描述】:
我在让 ggplot2 按我的意愿工作时遇到了一点麻烦。基本上,我想通过将它们放在一个图中来比较实际观察结果与近似值。例如,
> library(ggplot2)
> df.actual <- data.frame(x = 1:100, y = (1:100) * 2)
> df.approx <- data.frame(x = 1:150, y = (1:150) * 2 + 5 + rnorm(150, mean = 3) )
> ggplot() + geom_point(aes(x, y), data = df.actual) + geom_line(aes(x,y), data = df.approx)
我的问题是我无法显示图例。我在某处读到 ggplot2 的图例不是很灵活(?)。理想情况下,一个带有
的图例- title = '类型'
- 键:黑色实心点和黑色线条
- 关键标签:“实际”、“近似”
- legend.position = 'topright'
谢谢。
【问题讨论】: