简体   繁体   中英

ggplot2 (scatter plot and several fitted values) in R

How I can modify the following code to have a plot between x and y (scatter plot) and the fitted values X0.025 and y=X0.975 as the curves (lines) on the plot. (please run plot(m6) to see the plot which I am looking for to make by 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)

I tried to make this plot by ggplot and here is the code:

 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()

在此处输入图片说明

Are you looking for this?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM