Tuesday, June 7, 2011

R - plotting means and Confidence Intervals

  • you need the package gplots, which requires the packages bitops and caTools, so install them using the command
    > install.packages(c("bitops","caTools","gplots"))
  • load gplots
    > library(gplots)
  • plotmeans(formula)

Example:
# Create a vector which will define the groups (1,2,...,10)

> x <- rep(1:10,10) # Create a vector consisting of 100 random values from a normal distribution > y <- rnorm(100) # Plotting > plotmeans(y~x)

  • If x and y are part of a dataframe my.df you have to specify the dataframe:
    plotmeans(y~x, data=my.df)
  • The default confidence interval is 95%; you can change it with the p argument:
    plotmeans(y~x, p=0.9) plots the mean with 90%-confidence intervals
  • changing the argument ci.label to TRUE adds the values the CIs, n.label works on the n's of the groups (above the x-axis)
  • you can also replace the circle for the mean by the value of the mean (via mean.labels=T)
  • the arguments ccol, barcol, col change the color of the line connecting the means, the bars, the text

Example:
# 50%-CI, labled CIs
> plotmeans(y~x, p=.5, main="50%", mean.labels=F, ci.label=T, n.label=F, ccol="red", barcol="green", col="darkgreen")

No comments :

Post a Comment