Plotting the confidence intervals using plotCI() function
In this method to plot the confidence intervals, the user needs to install and import the plotrix package to use its functionalities in the working R console, and then the user needs to call the plotCI() function with the data as the parameters of the function and further its function will directly plot the plot with the confidence intervals included in it in the R programming language.
To install and import the ggplot2 package in the R console, the user must follow the below syntax:
install.packages("plotrix") library("plotrix")
- plotCI function: Given a set of x and y values and interval width or upper and lower bounds, plot the points with error bars.
Syntax: plotCI(x, y = NULL,ui, li, err=’y’, … )
Parameters:
- x,y: Coordinates for the center of error bars. y defaults to 1:n.
- UI: upper end of error bars.
- li: lower end of error bars.
- …: other plotting parameters.
Example: In this example, we will be using the plotCI() function to plot the confidence intervals in the plot of the given data in the R programming language.
R
# Import plotrix library library ( "plotrix" ) # Create Data gfg<- round ( data.frame (x = 1:20, y = runif (20, 20, 40), low = runif (20, 0, 20), up = runif (20, 40, 50)), 4) # Create plotrix plot with confidence intervals plotCI (x = gfg$x,y = gfg$y,li = gfg$low,ui = gfg$up) |
Output:
How to Plot a Confidence Interval in R?
In this article, we will discuss how to plot confidence intervals in the R programming language.