Boxplot schmoxplot: How to plot means and standard errors conditioned by a factor in R?

后端 未结 5 1189
孤独总比滥情好
孤独总比滥情好 2020-12-13 15:57

We all love robust measures like medians and interquartile ranges, but lets face it, in many fields, boxplots almost never show up in published articles, while means and sta

5条回答
  •  一个人的身影
    2020-12-13 16:29

    This question is almost 2 years old now, but as a new R user in an experimental field, this was a big question for me, and this page is prominent in google results. I just discovered an answer I like better than the current set, so I thought I'd add it.

    the package sciplot makes the task super easy. It gets the job done in a single command

    #only necessary to get the MPG dataset from ggplot for direct comparison
    library(ggplot2)
    data(mpg)
    attach(mpg)
    
    #the bargraph.CI function with a couple of parameters to match the ggplot example
    #see also lineplot.CI in the same package
    library(sciplot)
    bargraph.CI(
      class,  #categorical factor for the x-axis
      hwy,    #numerical DV for the y-axis
      year,   #grouping factor
      legend=T, 
      x.leg=19,
      ylab="Highway MPG",
      xlab="Class")
    

    produces this very workable graph with mostly default options. Note that the error bars are standard errors by default, but the parameter takes a function, so they can be anything you want! sciplot bargraph.CI with mpg data

提交回复
热议问题