Home > Net >  How to use geom_ribbon()?
How to use geom_ribbon()?

Time:01-28

Here is my example.

library(ggplot2)

my_df <- data.frame(x = c(1,2,3), y = c(4,5,6), y_min = c(1,1,2), 
                    y_max = c(7,8,8))
ggplot(data = my_df) 
    geom_line(aes(x = x, y = y, color = "blue"))  
    geom_ribbon(aes(ymin =y_min, ymax =y_max, x= x), fill = "grey70") 

I would like to get back something resembling line plot and confidence interval around it, but I am only getting confidence interval (ribbon) not the main line.

enter image description here

What am I missing?

CodePudding user response:

We could set alpha = 0.3 to see the line and change grey70 to grey grey12:

ggplot(my_df)   geom_line(aes(y=y, x=x, colour = "blue")) 
  geom_ribbon(aes(ymin=y_min, ymax=y_max, x=x, fill = "band"), alpha = 0.3) 
  scale_colour_manual("",values="blue") 
  scale_fill_manual("",values="grey12")

enter image description here

  •  Tags:  
  • Related