【发布时间】:2014-09-14 15:11:09
【问题描述】:
我正在尝试将 xvar 中位数显示为虚线并在图例中显示。这是我的代码:
require(ggplot2)
require(scales)
medians_mtcars <- data.frame("wt.median"=median(mtcars$wt))
# legend shows but linetype is wrong (solid)
p <- ggplot(mtcars, aes(wt, mpg))
p <- p + geom_point()
p <- p + geom_vline(aes(xintercept=wt.median, linetype="dotted"),
data=medians_mtcars, show_guide=TRUE)
p
我也试过了:
# linetype is correct but legend does not show
p <- ggplot(mtcars, aes(wt, mpg))
p <- p + geom_point()
p <- p + geom_vline(aes(xintercept=wt.median),
data=medians_mtcars, show_guide=TRUE, linetype="dotted")
p
本来想发布剧情图片,但尚未超过声誉阈值。
此论坛上还有 2 个其他帖子与此主题相近,但没有提供解决此问题的方法: Add vline to existing plot and have it appear in ggplot2 legend? ; Incorrect linetype in legend, ggplot2 in R
我正在使用 ggplot2 版本 1.0.0
我做错了什么?
提前致谢
【问题讨论】: