I am trying to plot data that I was given. This data comes from a model and includes the mean of a variable, 2.5% and 97.5% CI of the variable, and I want to plot it with a line for the median (geom_line) and a ribbon for the CI (geom_ribbon).
I have made plots like this with other data and I get a nice smooth graphs for both the line and the ribbon, but with the new data set I get "steps" for both the line and the ribbon, similar to the example I have produce here.
Is there any way to make the ribbons smooth? Is this because the number of data points is not big enough to make it smooth?
Any ideas will be much appreciated! I run out of examples already posted on-line and none is working for me... THANKS in advance!
require(tidyverse)
#> Loading required package: tidyverse
library(airqualityES)
airqualityBEA <- airquality%>%
arrange(desc(Temp))%>%
mutate(list = 1:153)
# This plot makes step in both the geom_line and geom_ribbon.
ggplot() +
geom_ribbon(data = airqualityBEA,
aes(x= list,ymin = Temp - 1, ymax = Temp+1),
fill = "#00798c", alpha = 0.5) +
geom_line(data =airqualityBEA,
aes(x= list, y=Temp),
alpha=1, size=0.5, color = "#00798c")
# Using Geom_smooth with loess instead of geom_line it improves the plot... (I cannot post a second image here :))
ggplot()+
geom_ribbon(data = airqualityBEA,
aes(x= list,ymin = Temp - 1, ymax = Temp+1),
fill = "#00798c", alpha = 0.5) +
geom_smooth(method = "loess", se = FALSE,
data =airqualityBEA,
aes(x= list, y=Temp),
alpha=1, size=0.5, color = "#00798c")
#> `geom_smooth()` using formula 'y ~ x'
Created on 2020-03-26 by the reprex package (v0.3.0)