Shading confidence intervals manually with ggplot2 in R Last Updated : 30 Jun, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to generate Shading confidence intervals manually with ggplot2 in R Programming language. Let us first draw a regular curve and then add confidence intervals to it. Example: R # Load Packages library("ggplot2") # Create a DataFrame for Plotting DF <- data.frame(X = rnorm(10), Y = rnorm(10)) # Plot the ggplot2 plot ggplot(DF, aes(X, Y)) + geom_line(color = "dark green", size = 2) Output: LineGraph using ggplot2 To add shading confidence intervals, geom_ribbon() function is used. Which displays a Y interval defined by ymin and ymax. It has aesthetic mappings of ymin and ymax. Other than that it also has some more parameters which are not necessary. Syntax : geom_ribbon(mapping, color, fill, linetype, alpha, ...) Parameters : mapping : aesthetic created by aes() to define ymin and ymax.color : Specifies the color of border of the Shading interval.fill : Specifies the color of Shading Confidence Interval.linetype : Specifies the linetype of the border of Confidence Interval.alpha : Specifies the Opacity of the Shading Interval.... : geom_ribbon also has other parameters such as data, stat, position, show.legend, etc. You can use them as per your requirements but in general case they are not useful as much. Return : Y interval with the specified range. Example: R # Load Packages library("ggplot2") # Create DataFrame for Plotting DF <- data.frame(X = rnorm(10), Y = rnorm(10)) # ggplot2 LineGraph with Shading Confidence Interval ggplot(DF, aes(X, Y)) + geom_line(color = "dark green", size = 2) + geom_ribbon(aes(ymin=Y+0.5, ymax=Y-0.5), alpha=0.1, fill = "green", color = "black", linetype = "dotted") Output: LineGraph with shading confidence intervals Comment More infoAdvertise with us Next Article Shading confidence intervals manually with ggplot2 in R E erkrutikpatel Follow Improve Article Tags : R Language R-ggplot Similar Reads Draw Confidence Interval on Histogram with ggplot2 in R A histogram is a graph that shows the distribution of a dataset. It can be used to estimate the probability distribution of a continuous variable, such as height or weight. To create a histogram, you need to divide the range of values into a series of intervals, called bins, and count the number of 6 min read How to Plot a Confidence Interval in R? In this article, we will discuss how to plot confidence intervals in the R programming language. Method 1: Plotting the confidence Interval using geom_point and geom_errorbar In this method to plot a confidence interval, the user needs to install and import the ggplot2 package in the working r conso 4 min read How to Find Confidence Intervals in R? The confidence interval in R signifies how much uncertainty is present in statistical data. a fundamental statistical technique, confidence intervals offer a range of likely values for an unknown population parameter based on sample data. They are essential to decision-making, hypothesis testing, an 6 min read Add confidence intervals to dotchart in R In statistics, confidence intervals are a type of interval estimate used to provide an estimate of the range of values that a population parameter, such as a mean or proportion, is likely to fall within. These intervals are essential for interpreting the results of statistical analyses and providing 9 min read Create interactive ggplot2 graphs with Plotly in R "A Picture is worth a thousand words," and that picture would be even more expressive if the user could interact with it. Hence the concept of "interactive graphs or charts. Interactive charts allow both the presenter and the audience more freedom since they allow users to zoom in and out, hover and 6 min read Like