- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a line chart with mean and standard deviation using ggplot2 in R?
Sometimes we have mean and standard deviation given for groups or factors, these are generally obtained from previous research studies and is referred to as the secondary data. In this case. the line chart with mean and standard deviation using ggplot2 can be created by defining the minimum and maximum inside geom_error function of ggplot2 package, where the difference between mean and standard deviation defines the standard deviation if the minimum is set as mean minus one standard deviation and the maximum is set as mean plus one standard deviation.
Example
Consider the below data frame −
Group<−c("G1","G2","G3","G4") Mean<−c(25,27,23,26) SD<−c(3.24,2.25,3.6,4.1) df<−data.frame(Group,Mean,SD) df
Output
Group Mean SD 1 G1 25 3.24 2 G2 27 2.25 3 G3 23 3.60 4 G4 26 4.10
Loading ggplot2 package and creating the plot with mean and standard deviation −
library(ggplot2) ggplot(df,aes(Group,Mean))+geom_errorbar(aes(ymin=Mean-SD,ymax=Mean+SD),width=0.2)+geom_line(group=1)+geom_point()
Output
- Related Articles
- How to create boxplot using mean and standard deviation in R?
- How to create a line chart using ggplot2 with a vertical line in R?
- How to create a line chart using ggplot2 with larger width in R?
- How to create line chart using ggplot2 in R with 3-sigma limits?
- How to create line chart for categories with grey color palette using ggplot2 in R?
- How to create bar chart using ggplot2 with chart sub-title in R?
- How to create a line chart using ggplot2 that touches the edge in R?
- How to create a point chart with empty points using ggplot2 in R?
- Create line chart for mean covered with minimum and maximum in R.
- How to find mean and standard deviation from frequency table in R?
- How to create a line chart for a subset of a data frame using ggplot2 in R?
- How to create the bar chart with ggplot2 using color brewer in R?
- PyTorch – How to normalize an image with mean and standard deviation?
- How to create a point chart for cumulative sums using ggplot2 in R?
- How to create a bar chart for single vector using ggplot2 in R?

Advertisements