R Lattice Xyplot Error Bars
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies lattice error bars of this site About Us Learn more about Stack Overflow the company error bars in r Business Learn more about hiring developers or posting ads with us Stack Overflow Questions 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. 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.frame(DateTime = as.POSIXct(c("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")), t.ws = c(32.7, 35.5, 37.1, 37.6, 38.7), mean.tort = c(32.4,
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 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, http://stackoverflow.com/questions/19975390/add-error-bars-seperately-in-lattice-line-plot 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 http://r.789695.n4.nabble.com/error-bars-in-lattice-xyplot-with-groups-td801398.html modified to depict # 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=sing
x,y numeric values, the points around which http://www.martin-elff.net/knitr/memisc/errbars.html error bars are plotted. x is https://www.r-bloggers.com/tag/xyplot/ a numeric vector, y is a matrix with three columns, the values, the lower and the upper ends of the error bars. ... graphical error bars parameters passed to panel.xy panel.xy panel function to produce the plot to which error bars are added make.grid character string, determines the direction of grid lines added to the plot r lattice xyplot ewidth numerical value, width of the whiskers of the error bars See Also panel.xyplot Examples library(lattice) library(grid) ## Don't show: if(interactive()) old.prompt <- grid::grid.prompt(TRUE) ## Error: 'grid.prompt' is not an exported object from 'namespace:grid' ## End Don't show applications <- Aggregate(percent(Dept,weight=Freq,ci=TRUE)~Gender, data=UCBAdmissions) admissions <- Aggregate( percent(Admit=="Admitted",weight=Freq,ci=TRUE)~Dept+Gender, data=UCBAdmissions) xyplot(cbind(Percentage,lower,upper)~Gender|Dept,data=admissions, panel=panel.errbars, ewidth=.2,pch=19, ylab="Percentage applicants admitted by Department") xyplot(cbind(Percentage,lower,upper)~Gender|Dept,data=applications, panel=panel.errbars, ewidth=.2,pch=19, ylab="Percentage applications to the Department") ## Don't show: if(interactive()) grid::grid.prompt(old.prompt) ## Error: 'grid.prompt' is not an exported object from 'namespace:grid' ## End Don't show [Package memisc version 0.97 Index]
by over 573 bloggers. There are many ways to follow us - By e-mail: On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here) Jobs for R-usersStatistical Analyst @ Rostock, Mecklenburg-Vorpommern, GermanyData EngineerData Scientist – Post-Graduate Programme @ Nottingham, EnglandDirector, Real World Informatics & Analytics Data Science @ Northbrook, Illinois, U.S.Junior statistician/demographer for UNICEF Popular Searches web scraping heatmap twitter maps time series animation boxplot shiny hadoop ggplot2 how to import image file to R trading finance LaTeX eclipse RStudio sql excel ggplot quantmod knitr googlevis pca market research rattle regression tutorial map coplot rcmdr Recent Posts Election 2016: Tracking Emotions with R and Python Data science for executives and managers The Worlds Economic Data, Shiny Apps and all you want to know about Propensity Score Matching! August Package Picks Slack all the things! Warsaw R-Ladies Notes from the Kölner R meeting, 14 October 2016 anytime 0.0.4: New features and fixes 2016-13 ‘DOM’ Version 0.3 Building a package automatically The new R Graph Gallery Network Analysis Part 3 Exercises Annotated Facets with ggplot2 Paper published: mlr - Machine Learning in R a grim knight [cont’d] Other sites SAS blogs Jobs for R-users Posts Tagged ‘ xyplot ' How to plot lattice and ggplot2 graphs with FastRWeb April 10, 2012By ronan With print() If you are an advanced R user, you probably know the lattice and the ggplot2 packages. They allow you to plot elegant graphics with less code (Hocking, 2009 and Sueur, 2010). If you know these two packages, you should hardly use plot() for your graphs. If you read my article on FastRWeb, you Read more » Plotting grouped data vs time with error bars in R October 31, 2011By Daniel Hocking This is my first blog since joiningR-bloggers. I’m quite excited to be part of this group and apologize if I boreany experienced R users with my basic