R Error Bars Lattice
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
Error Bars In R
the workings and policies of this site About Us Learn more about geom_errorbar Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions lattice xyplot error bars Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Ggplot2
Join them; it only takes a minute: Sign up Add error bars seperately in lattice line-plot? up vote 0 down vote favorite 2 I have a line-plot produced with lattice's xyplot. It contains two types of temperatures measured, one of these are mean values. Therefore, I would like to add standard errors to these points (t.tort). Unfortunately, doing this seperately does not work using (Hmisc)errbar... here is what I have come up with so far: xyplot(mean.tort+t.ws~DateTime, pre, type=c("a", "p"), col=c("red", "blue"), main="Pre-Translocation", xlab=list(label="Date and Time", cex=1), ylab=list(label="Temperature (°C)", cex=1), scales = list(tck = c(1, 0), x=list(cex=0.8, rot=45, tick.number=40), y=list(cex=0.8, tick.number=8, limits=c(29,43))), key=list(text=list(c("Tortoise","Ambient")), lines=list(col=c("red", "blue"),type="l"), corner=c(0.5,0.92))) errbar(x=pre$DateTime, y=pre$mean.tort, yplus=pre$mean.tort+pre$se.tort,yminus=pre$mean.tort-pre$se.tort, add=T, col="red") And the important bits of my data frame are as follows: pre$DateTime<-c(as.POSIXct("2013-01-27 09:00:00" "2013-01-27 10:00:00" "2013-01-27 11:00:00" "2013-01-27 12:00:00" "2013-01-27 13:00:00") pre$t.ws<-c(32.7, 35.5, 37.1, 37.6, 38.7) pre$mean.tort<-c(32.4, 34.9, 35.1, 36.8, 37.7) pre$se.tort<-c(0.825, 0.84, 0.21, 0.228, 0.28) I got a bit frustrated with this, so any suggestions will be greatly appreaciated. Thank you very much for your efforts in advance! r lattice line-plot share|improve this question edited Nov 15 '13 at 7:42 asked Nov 14 '13 at 10:35 LeoTor 156 You can't mix base and grid graphics. Have you looked around? stackoverflow.com/questions/2381618/… –Roman Luštrik Nov 14 '13 at 12:21 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted Try this Your data: pre = data
[ date ] [ thread ] [ subject ] [ author ] Dear Deepayan and Sundar, Thank you so much for your help with this. However, I may have phrased my problem too specifically, assuming that *in general* I could apply your response to all Lattice graphics. What I need is a barchart or vertical dotchart, with error bars, across three treatments, with a form that should look something like: barchart(median~fac1|by1, groups=group1). Your solution works great with the problem I had posed
this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ error bars in lattice xyplot *with groups* Hi all, I'm trying to plot error bars in a lattice plot http://r.789695.n4.nabble.com/error-bars-in-lattice-xyplot-with-groups-td801398.html generated with xyplot. Deepayan Sarkar has provided a very useful solution for simple circumstances (https://stat.ethz.ch/pipermail/r-help/2005-October/081571.html), yet I am having trouble getting it to work when the "groups" setting is enabled in xyplot (i.e. multiple lines). To illustrate this, consider the singer data generated by the above linked solution previously submitted: ##################### library(lattice) singer.split <- with(singer, split(height, voice.part)) singer.ucl <- sapply(singer.split, error bars function(x) { st <- boxplot.stats(x) c(st$stats[3], st$conf) }) singer.ucl <- as.data.frame(t(singer.ucl)) names(singer.ucl) <- c("median", "lower", "upper") singer.ucl$voice.part <- factor(rownames(singer.ucl), levels = rownames(singer.ucl)) #now let's split up the voice.part factor into two factors, singer.ucl$voice=factor(rep(c(1,2),4)) singer.ucl$range=factor(rep(c("Bass","Tenor","Alto","Soprano"),each=2)) #here's Deepayan's previous solution, slightly modified to depict # r error bars the dependent variable (median) and the error bars on the y-axis # and the independent variable (voice.part) on the x-axis prepanel.ci <- function(x, y, ly, uy, subscripts, ...) { x <- as.numeric(x) ly <- as.numeric(ly[subscripts]) uy <- as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci <- function(x, y, ly, uy, subscripts, pch = 16, ...) { x <- as.numeric(x) y <- as.numeric(y) ly <- as.numeric(ly[subscripts]) uy <- as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = "black", length = 0.25, unit = "native", angle = 90, code = 3) panel.xyplot(x, y, pch = pch, ...) } #this graph works xyplot(median ~ voice.part, data=singer.ucl, ly = singer.ucl$lower, uy = singer.ucl$upper, prepanel = prepanel.ci, panel = panel.ci, type="b" ) #this one does not (it will plot, but will not seperate the groups) xyplot(median ~ voice, groups=range, data=singer.ucl, ly = singer.