比方说,我并不需要一个“适当的”变量映射,但仍希望有传说密钥来帮助图表的理解。我的实际数据是类似于以下DF不同的传说,钥匙,GGPLOT2
df <- data.frame(id = 1:10, line = rnorm(10), points = rnorm(10))
library(ggplot2)
ggplot(df) +
geom_line(aes(id, line, colour = "line")) +
geom_point(aes(id, points, colour = "points"))
基本上,我想传说相对于points
关键是..只是一个点,没有中间行。我已经接近与此:
library(reshape2)
df <- melt(df, id.vars="id")
ggplot() +
geom_point(aes(id, value, shape = variable), df[df$variable=="points",]) +
geom_line(aes(id, value, colour = variable), df[df$variable=="line",])
但它定义了两个独立的图例。固定第二码(具有重塑我的数据)将被罚款过,但我更喜欢的方式(如果有的话)手动更改任何图例项(并继续使用第一计算策略)。谢谢!
编辑:
感谢您@alexwhan刷新约变量映像我的记忆中。然而,到目前为止,我已经得到了最简单的方法仍然是以下(非常糟糕的劈!):
df <- data.frame(id = 1:10, line = rnorm(10), points = rnorm(10))
ggplot(df) +
geom_line(aes(id, line, colour = "line")) +
geom_point(aes(id, points, shape = "points")) +
theme(legend.title=element_blank())
这只是躲藏在两个不同传说的称号。
其他想法多人欢迎!
很不错的方法。可能是最好的一个。我只是想等别人,但它似乎也是唯一一个:-)。无论如何,非常感谢! – Michele 2013-05-16 10:17:35