'connect step function to 0 and max y

Using this code as example:

df <- data.frame(
        x = c(30, 40, 20, 60)
        , y = c(10, 20, 5, 70)
        , group = c("g1", "g1", "g2", "g2") 
    )

options(repr.plot.width = 10, repr.plot.height = 7) 
ggplot() +
    geom_point(data=df, aes(x=x, y=y, group=group, color=group)) +
    geom_step(data=df, aes(x=x, y=y, group=group, color=group), size=1) +
    scale_y_continuous(breaks = round(seq(0, 100, by = 5), 1)) +
    coord_cartesian(ylim = c(0, 100))

It produces:

enter image description here

Is there an easy way in ggplot (?) to achieve the following (only indicated by one step function):

enter image description here

Or do I need to change original data and somehow impute? Hope this makes sense? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source