Error bar ends missing

前端 未结 2 1340
温柔的废话
温柔的废话 2021-01-22 05:11

The following example code:

require(ggplot2)

stats <- data.frame(Day=0:5, Mean=c(3.2, 2.7, 0.8, 0.2, 0, 0), Q10=0.0, Q90=c(7.48, 4.0, 2.2, 1.2, 0, 0))

plot          


        
相关标签:
2条回答
  • 2021-01-22 05:59

    The problem is with your scale_x_continuous() statement. You set the limits= starting from 0 but for the first bar "T" is outside this limit so it is removed (you the warning that for geom_path() one row is removed). If you set limits= to for example star from -0.3 then "T" appears.

      + scale_x_continuous("Day", expand=c(0.02,0), limits=c(-0.3,15), 
            breaks=0:15, labels=c("DOS", 1:15))
    

    enter image description here

    0 讨论(0)
  • 2021-01-22 06:06

    Note the warning:

    Warning message:
    Removed 1 rows containing missing values (geom_path).
    

    Use coord_cartesian to specify limits without discarding data:

    plot <- ggplot(stats, aes(x=Day, y=Mean)) +
      geom_point(size=4) +
      geom_line(size=1.5) +
      geom_errorbar(aes(ymin=Q10, ymax=Q90), width=0.2) +
      ggtitle("Example") +
      ylab("Pain Score") +
      scale_x_continuous("Day", breaks=0:15, labels=c("DOS", 1:15)) +
      scale_y_continuous("Pain Score",  breaks=0:10) +
      coord_cartesian(xlim = c(-0.3, 15.3), ylim = c(-0.3,10.3))
    
    print(plot)
    
    0 讨论(0)
提交回复
热议问题