Easy Error Bars with R and Plotly

March 25, 2015

(This article was first published on Modern Data » R, and kindly contributed to R-bloggers)

Error bars are a great way to visually represent variability of a dataset, and are easy to graph with Plotly and R! Error bars can be used to visualize standard deviations, standard errors or confidence intervals (just don’t forget to specify which measure the error bar in the graph represents).

Below are two examples that demonstrate how to graph a variety of error bars. The complete R script and data used to create these 2 graphs are available here!

To create vertical error bars, like on the Snow line in the graph below, set
error_y = list(
          type = "data",
          array = c(YOUR_VALUES))

It is also possible to calculate and plot error bars with a percent value, like on the Rain line below. Set:
error_y = list(
          type = "percent",
          value = CHOOSE_%_VALUE)

To create horizontal error bars use error_x. Furthermore, it’s easy to graph asymmetrical error bars. Just set symmetric = FALSE and add an arrayminus array like this:

error_x = list(
          type = "data",
          symmetric = FALSE,
          array = c(YOUR_HIGH_VALUES),
          arrayminus = c(YOUR_LOW_VALUES))

Creating dashboards or visualizations at your company? Consider Plotly Enterprise for modern intracompany graph and data sharing.

To leave a comment for the author, please follow the link and comment on their blog: Modern Data » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)