Reputation: 129
I have the following figure in R, generated using the ggplot2 package which resulted in the following:
The code to obtain this plot is:
df <- data.frame(value_x = c(10,20,30,40), value_y = c(89.3, 89.4, 89.60, 90.1))
myplot <- ggplot(data = df, aes(x = value_x, y = value_y)) +
geom_point() +
geom_line()
myplot
Now I want to fill the area under this curve, but still keep the y-axis scale.
When I add geom_area(alpha = 0.40)
to the code, the plot becomes the following:
As you can see, the area runs from 0 to the curve, which rescales the y-axis. How can I inhibit this from happening?
Upvotes: 0
Views: 323
Reputation: 26353
I suggest the use of geom_ribbon
which understands ymin
and ymax
aesthetics. Unlike geom_area
which gives a continuous bar plot that starts at 0.
myplot +
geom_ribbon(aes(ymin = min(value_y), ymax = value_y))
Upvotes: 2