Create geom_ribbon for min-max range

后端 未结 1 1637
误落风尘
误落风尘 2021-01-19 00:32

Given the following data:

df<-data.frame(
  year=(1996:2000),
  a=c(2,1.5,1.5,2,3),
  b=c(2,2,2,3,4),
  c=c(2,3,3,1,1))

with ggplot:

相关标签:
1条回答
  • 2021-01-19 00:46

    What about first computing the mininum and maximum values:

    df$min <- apply(df[, -1], 1, min)
    df$max <- apply(df[, -1], 1, max)
    

    And then simply plotting the ribbon:

    ggplot(df, aes(x = year, ymin = min, ymax = max)) + geom_ribbon()
    

    ggplot2 ribbon example

    0 讨论(0)
提交回复
热议问题