R中的ggplot2(散点图和几个拟合值)

时间:2018-02-08 22:19:30

标签: r ggplot2

如何修改以下代码,使得x和y之间的图(散点图)和拟合值X0.025和y = X0.975作为图上的曲线(线)。 (请运行plot(m6)查看我想要ggplot制作的情节

library(quantregGrowth)
data(growthData)
m6<-gcrq(y~ps(x, lambda=seq(0,100,l=20)), tau=c(0.025,0.975), n.boot=10, 
data=growthData) 
plot(m6)

我试图通过ggplot创建这个图,这里是代码:

 library(ggplot2)
    library(plotly)
    temp <- data.frame(m6$fitted)
    growthData_b <- cbind(growthData, temp)

    a <- ggplot(data=growthData_b, aes(x, y=X0.025)) + geom_line() + 
    geom_line(data=growthData_b, aes(x, y=X0.975), color = "red")  + theme_bw()

enter image description here

1 个答案:

答案 0 :(得分:0)

你在找这个吗?

ggplot(data=growthData_b, aes(x, y=X0.025)) + 
geom_line() + 
geom_line(data=growthData_b, aes(x, y=X0.975), color = "red", linetype = 2)  + 
theme_bw() + 
geom_point(aes(x=x, y=y), shape = 1)