Skip to content

new geom suggestion: separate lines for upper and lower intervals #3503

Closed
@weiyangtham

Description

@weiyangtham

I'm wondering if there's room for a new geom that can produce the following graph

library(tidyverse)

# Example data
df <- tibble(y = c(0, 0, 0, 0, 0, 1, 1.5, 1.7, 1.8), 
             upper_y = y + 0.2, 
             lower_y = y - 0.2,
             year = -4:4)

p <- ggplot(df, aes(year, y)) + geom_line()

# geom_errorline would simplify this
p + 
  geom_line(aes(y = upper_y), linetype = 2) +
  geom_line(aes(y = lower_y), linetype = 2)

image

So instead of having to use geom_line twice, you could instead do

ggplot(df, aes(year, y, ymax = upper_y, ymin = lower_y)) + geom_errorline()

and this would fit more neatly into the idea of mapping the upper and lower intervals to the ymin and ymax aesthetics.

I imagine there's a way to achieve that same plot with geom_ribbon or geom_area but I haven't been able to do so so I'm guessing it wouldn't be straightforward even if there is.

Here is a prototype I wrote a few years ago: https://github.com/weiyangtham/econothemes

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions