ggplot: remove lines at ribbon edges

后端 未结 4 1321
别跟我提以往
别跟我提以往 2021-02-11 12:19

I am using ggplot to plot time course data (fixation proportions over time to different objects on the screen) and want to use a ribbon to show the SE, but the ribb

相关标签:
4条回答
  • 2021-02-11 13:01

    geom_ribbon understands linetype aesthetic. If you want to map linetype to a variable include it in the aes() argument, otherwise, place linetype outside and just give it 0, like so:

    ggplot(d, aes(Time, y, color = Object, fill = Object)) +
      geom_line(size = 2) +
      geom_ribbon(aes(ymin = lower, ymax = upper), linetype = 0, alpha = .3)
    

    More info here: http://docs.ggplot2.org/current/geom_ribbon.html

    0 讨论(0)
  • 2021-02-11 13:06

    Here you go

    ggplot(d, aes(Time, y,  fill=Object)) + 
      geom_line(size=2, aes(colour = Object)) + 
      geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.3)
    
    0 讨论(0)
  • 2021-02-11 13:07

    ggplot2's geom_ribbon() now includes an outline.type argument that helps control how the ribbon outlines are displayed.

    Outline Type

    library(tidyverse)
    
    huron <- tibble(year = 1875:1972, level = as.vector(LakeHuron))
    
    huron %>%
        ggplot(aes(year, level)) +
        geom_ribbon(aes(ymin = level - 1, ymax = level + 1), 
                    fill = "grey70", color = "red", 
                    outline.type = "lower") +
        geom_line(aes(y = level))
    

    Created on 2020-05-28 by the reprex package (v0.3.0)

    Linetype = 0

    Alternatively, as suggested we can set linetype = 0 to remove all lines.

    library(tidyverse)
    
    huron <- tibble(year = 1875:1972, level = as.vector(LakeHuron))
    
    huron %>%
        ggplot(aes(year, level)) +
        geom_ribbon(aes(ymin = level - 1, ymax = level + 1), 
                    fill = "grey70", color = "red", linetype = 0) +
        geom_line(aes(y = level))
    

    Created on 2020-05-28 by the reprex package (v0.3.0)

    0 讨论(0)
  • 2021-02-11 13:27

    You can remove the border using the colour argument:

    ggplot(d, aes(Time, y, color = Object, fill = Object)) +
      geom_line(size = 2) +
      geom_ribbon(aes(ymin = lower, ymax = upper), alpha = .3, colour = NA)
    

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