我想将部分线(不要扩展整个图)添加到散点图中。我有两个单独的图为此工作,但无法弄清楚如何将它们连接在一起:
第一个情节 -
p = qplot(x, y, data=data) + theme_bw() + theme(aspect.ratio=1)
lines = data.frame(x = c(-2,-2,5), y = c(0,2,2))
第二个情节 -
lines = data.frame(x = c(-2,-2,5), y = c(0,2,2))
base = ggplot(lines, aes(x, y))
base + geom_path(size = 1)
如何叠加它们?感谢。
答案 0 :(得分:0)
你可以尝试:
p = qplot(x, y, data=data) + theme_bw() + theme(aspect.ratio=1)
lines = data.frame(x = c(-2,-2,5), y = c(0,2,2))
p+geom_line(data = lines, aes(x=x, y=y))
采用示例数据集mydf
:
Dept <- c("Res","Bankings","Customer","Legal","Collection","Business")
YScore <- c(1,2,3,1,2,3)
XScore <- c(2,1,3,1,2,4)
mydf<-data.frame(Dept,YScore,XScore)
p = qplot(XScore, YScore, data=mydf) + theme_bw() + theme(aspect.ratio=1)
lines = data.frame(x = c(-2,-2,5), y = c(0,2,2))
p+geom_line(data = lines, aes(x=x, y=y))