I am starting to work with R, this has to be a basic question but it doesn't seem obvious how to do it easily. If I have the following data set :
x y
0,1
0,2
1,2
1,4
and so on, so there are multiple y values for each x value. This how can I easily do a plot showing the data and the means and the CI intervals.
I can do it, as I have hodged together a solution off by hacking bits of code together, but there has to be a simpler solution.
This is what I am doing with this very simple data file
cardboard,r1,r2,r3,r4,r5,r6
0,233,130,110,140,160
101,293,340,313,260,366,38
and this mess of code :
er <- read.csv(file="ianevans.csv",head=TRUE,sep=",")
er[,2:7] <- min(er[1,2:7],na.rm=TRUE)/er[,2:7]*100
er$sharpness[1]=mean(as.vector(er[1,2:7], "numeric"),na.rm=TRUE)
er$sharpness[2]=mean(as.vector(er[2,2:7], "numeric"),na.rm=TRUE)
er$se[1]=sd(as.vector(er[1,2:7], "numeric"),na.rm=TRUE)/sqrt(6-1)
er$se[2]=sd(as.vector(er[2,2:7], "numeric"),na.rm=TRUE)/sqrt(6-1)
p <- ggplot(er,aes(x=cardboard,y=sharpness))
p1 <- p + geom_point(aes(y=sharpness,color="red",size=5) )
p2 <- p1 +
scale_shape_discrete(solid=F) +
geom_point(aes(y=r1),color="blue",shape="o",size=3) +
geom_point(aes(y=r2),color="blue",shape="o",size=3) +
geom_point(aes(y=r3),color="blue",shape="o",size=3) +
geom_point(aes(y=r4),color="blue",shape="o",size=3) +
geom_point(aes(y=r5),color="blue",shape="o",size=3) +
geom_point(aes(y=r6),color="blue",shape="o",size=3)
p3 <- p2 +
geom_errorbar(aes(ymax=sharpness+se,ymin=sharpness-se),width=5)
Again this works, more or less, but as you can see there are a bunch of hard coded numbers and there has to be a better way to both have the data file set up and do the plots and easily be able to deal with different amounts of y data for each x data for example. The way some of the data manipulation is done is also awkward as it should be possible do to it without individual references for the means, sd's, .