另一個ggplot圖例問題!刪除ggplot中的圖層圖例
我有形式
test <- data.frame(
cond = factor(rep(c("A", "B"), each=200)),
value = c(rnorm(200), rnorm(200, mean=0.8))
)
所以兩組,一些值的數據集,我要繪製的密度。我還想添加一行表示每個組的情節平均所以我:
test.cdf <- ddply(test, .(cond), summarise, value.mean=mean(value))
然後在ggplot電話:
ggplot(test, aes(value, fill=cond)) +
geom_density(alpha=0.5) +
labs(x='Energy', y='Density', fill='Group') +
opts(
panel.background=theme_blank(),
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank(),
panel.border=theme_blank(),
axis.line=theme_segment()
) +
geom_vline(data=test.cdf, aes(xintercept=value.mean, colour=cond),
linetype='dashed', size=1)
如果你運行上面的代碼,你會得到一個傳說指示每個組,也是一個平均指標vline。我的問題是如何擺脫geom_vline()
的傳說?
您已將'cond'映射爲填充以及顏色。刪除其中一個映射應該可以解決問題。 – Andrie 2012-03-26 14:12:32
我的答案是否對你有用? – 2012-03-27 13:34:47