Skip to content

points(x,y), mean and standard deviation

5 messages · Jim Lemon, ashz, Joshua Wiley +1 more

#
Hi,

I have a data set with 3 rows (X=date, Y1=arithmetic mean and Y2=standard
deviation). How can I create a graph(e.g., points) which will show the
+-stdev as well (similar to excel).

Thanks
#
On 10/19/2010 07:41 PM, ashz wrote:
Hi ashz,
See FAQ 7.38.

Jim
#
Hi,

Thanks for the tip.

I run this script:
means.cl <- c(82, 79, 110, 136,103)
stderr.cl <- c(8.1,9.2,7.4,1.6,7.6)
plotCI(x = means.cl , uiw =  stderr.cl, pch=24)

But how can I connect the mean triangles with a line?

Thanks
#
Hi,

Here is an example using ggplot2.  For future reference, it would be
convenient if you provided sample data.  This is actually pretty easy
to do:  dput(yourdata) or if your data is very large:
dput(head(yourdata)).  At any rate, here is an example with the means
plotted as points and connected with a line and error bars around
them.  The line is controlled by geom_line() so you can easily add or
remove it.


# Load ggplot2
library(ggplot2)

# Create some sample data
dat <- data.frame(X = as.Date(Sys.time()) - 0:10,
                  Y1 = sample(20:30, 11, replace = TRUE),
                  Y2 = sample(2:6, 11, replace = TRUE))

# Actual plot
ggplot(data = dat, aes(x = X, y = Y1, ymin = Y1 - Y2, ymax = Y1 + Y2)) +
  geom_point() + # points at the means
  geom_line() + # if you want lines between pints
  geom_errorbar() # error bars, Y1 - Y2 and Y1 + Y2

HTH,

Josh
On Tue, Oct 19, 2010 at 1:41 AM, ashz <ashz at walla.co.il> wrote: