A line plot is a graphical representation of a series of data. Line plots are widely used in data visualization. In we use ggplot2( ) and plot( ) function to create line plot. Error bars act as a visual enhancement that help us to see variability of the plotted data. Error Bars are used to show standard error, standard deviation i.e. with the help of integrated error bars in our plot we can know the estimated error.
In this article we are going to create a line plot with Error Bars and without Error Bars. We can use plot() function to create scatter plot and line plot also.
errbar(x, y, yplus, yminus, cap=0.015, main = NULL, sub=NULL, xlab=as.character(substitute(x)), ylab=if(is.factor(x) || is.character(x)) ” “else as.character(substitute(y)), add=FALSE, lty=1, type=’p’, ylim=NULL,pch, lwd=1, errbar.col, )
|1.||x||It holds vector of x-axis values.|
|2.||y||It holds vector of y-axis values.|
|3.||yplus||The top value of error bars.|
|4.||yminus||The bottom value of error bars.|
|5.||cap||It is the width of cap|
|6.||main||The title of the plot|
|7.||sub||The title of sub plot|
|10.||add||Used to add error bars to existing plot set it to True.|
|11.||lty||The line type for error bars.|
|15.||errbar.col||To change the color of error bars|
- Firstly open up your rstudio
- Type the following command and hit enter to install the dependency that will help us to draw error bars in line plots.
- Load library by typing :
- Create two data variables one for the x-axis and another for the y-axis
- Create a vector to store error values (randomly)
- Show error bars using errbar()
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.