【发布时间】:2015-09-28 23:23:17
【问题描述】:
我有一些代码绘制了一些值的直方图,以及一些水平线来表示要比较的参考点。但是, ggplot 不会为线条生成图例。
library(ggplot2)
library(dplyr)
## Siumlate an equal mix of uniform and non-uniform observations on [0,1]
x <- data.frame(PValue=c(runif(500), rbeta(500, 0.25, 1)))
y <- c(Uniform=1, NullFraction=0.5) %>% data.frame(Line=names(.) %>% factor(levels=unique(.)), Intercept=.)
ggplot(x) +
aes(x=PValue, y=..density..) + geom_histogram(binwidth=0.02) +
geom_hline(aes(yintercept=Intercept, group=Line, color=Line, linetype=Line),
data=y, alpha=0.5)
我什至尝试将问题简化为仅绘制线条:
ggplot(y) +
geom_hline(aes(yintercept=Intercept, color=Line)) + xlim(0,1)
我仍然没有得到传说。谁能解释为什么我的代码没有生成带有图例的图?
【问题讨论】: