R Add Error Bars To Scatter Plot
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us error bars in r barplot Learn more about Stack Overflow the company Business Learn more about hiring developers error.bar function r or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack errbar r 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 Scatter plot with error bars up vote 21 r ggplot error bars down vote favorite 11 How can I generate the following plot in R? Points, shown in the plot are the averages, and their ranges correspond to minimal and maximal values. I have data in two files (below is an example). x y 1 0.8773 1 0.8722 1 0.8816 1 0.8834 1 0.8759 1 0.8890 1 0.8727 2 0.9047 2 0.9062 2 0.8998 2 0.9044 2 0.8960 ..
R Summaryse
... r plot share|improve this question edited Oct 23 '12 at 15:10 Roland 74.2k463103 asked Oct 23 '12 at 14:29 sherlock85 1521313 Since you clearly don't want a boxplot, I changed the title of your question in order to reflect what you really want. –Roland Oct 23 '12 at 15:11 1 also plotrix::plotCI, gplots::plotCI, library("sos"); findFn("{error bar}") –Ben Bolker Oct 23 '12 at 17:29 add a comment| 5 Answers 5 active oldest votes up vote 52 down vote accepted First of all: it is very unfortunate and surprising that R cannot draw error bars "out of the box". Here is my favourite workaround, the advantage is that you do not need any extra packages. The trick is to draw arrows (!) but with little horizontal bars instead of arrowheads (!!!). This not-so-straightforward idea comes from the R Wiki Tips and is reproduced here as a worked-out example. Let's assume you have a vector of "average values" avg and another vector of "standard deviations" sdev, they are of the same length n. Let's make the abscissa just the number of these "measurements", so x <- 1:n. Using these, here come the plotting commands: plot(x, avg, ylim=range(c(avg-sdev, av
deparse(substitute(x)), ylab= deparse(substitute(y)), ...) r arrows Arguments x vector of x values. y vector of plot mean and standard deviation in r y values. yplus vector of y values: the tops of the error bars. yminus vector http://stackoverflow.com/questions/13032777/scatter-plot-with-error-bars of y values: the bottoms of the error bars. cap the width of the little lines at the tops and bottoms of the error bars in units of the width http://artax.karlin.mff.cuni.cz/r-help/library/sfsmisc/html/errbar.html of the plot. Default is 0.015. ylim (numeric of length 2): the y-axis extents with a sensible default. xlab, ylab axis labels for the plot, as in plot.default. ... Graphical parameters (see par) may also be supplied as arguments to this function. Author(s) Originally Charles Geyer, U.Chicago, early 1991; then Martin Mächler. See Also errbar in package Hmisc is similar. Examples y <- rnorm(10); d <- 1 + .1*rnorm(10) errbar(1:10, y, y + d, y - d, main="Error Bars example") [Package sfsmisc version 1.0-20 Index]
instant chat support from our awesome https://plot.ly/r/error-bars/ engineering team. plotly Pricing PLOTCON NYC API Sign In SIGN UP + NEW PROJECT UPGRADE REQUEST DEMO Feed Pricing Make https://stat.ethz.ch/pipermail/r-help/2000-November/009029.html a Chart API Sign In SIGN UP + NEW PROJECT UPGRADE REQUEST DEMO Show Sidebar Hide Sidebar Help API error bars Libraries R Error Bars Fork on Github Navigation Back to R Error Bars in R How to add error bars to scatter plots in R. R matplotlib Python plotly.js Pandas node.js MATLAB Error Bars library(dplyr) r add error ## Warning: package 'dplyr' was built under R version 3.2.5 library(plotly) ## Warning: package 'ggplot2' was built under R version 3.2.4 data <- mpg %>% group_by(class) %>% summarise(highway = mean(hwy), sd = 1.96 * sd(hwy), city = mean(cty)) %>% arrange(desc(highway)) %>% tidyr::gather(key, value That's certainly a simpler solution. It might be worth wrapping a few arrows() calls up in some kind of simple errorbar function (just so it's slightly more accessible to newcomers). The only two things my function did that these calls don't do is (1) to size the plot appropriately so the upper and lower limits of the errors are within the plot, (2) to draw the segments/arrows first so that one can add points with pch=19 and bg=par("bg") to get open points without lines going through them. On Thu, 9 Nov 2000, Emmanuel Paradis wrote: > At 14:07 08/11/00 -0500, Ben Bolker wrote: > > > > I'm going to take the liberty of reposting this function, which is based > >on one that Bill Venables posted a while back. I've tweaked with it a bit > >to add functionality. It will do horizontal bars or vertical bars, but > >not (yet) both simultaneously (the hardest thing about that is deciding on > >what format you want the data supplied in). > > > > There's also a help file supplied below. > > > > Should this (after appropriate tweaking/polishing/testing/revision) go > >into the main R code base? It seems like a pretty basic function to me > >... > > [...] > > >On Wed, 8 Nov 2000, Mike Beddo wrote: > > > >> I'm a newcomer to R. I can't seem to find any documentation how to add > >> error bars to points in scatter plots. I guess I could plot the points, > >> then compute and plot line segments in the X and/or Y directions to > >> represent the errors? > >> > >> - Mike > > I think using arrows(..., code=3, angle=90, ...) is quite simple, e.g.: > > x <- rnorm(10) > y <- rnorm(10) > se.x <- runif(10) > se.y <- runif(10) > plot(x, y, pch=22) > arrows(x, y-se.y, x, y+se.y, code=3, angle=90, length=0.1) > arrows(x-se.x, y, x+se.x, y, code=3, angle=90, length=0.1) > > The first arrows() draws the error bars for y, and the second one for x, > 'code=3' draws a head at both ends of the arrow, 'angle=' is the angle of > the head with the main axis of the arrow, and 'length=' is the length of > the head. You can also add usual graphic parameters (col, lwd, ...). > > > Emmanuel Paradis > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > S