VOOZH about

URL: https://www.geeksforgeeks.org/r-language/plot-shaded-area-between-vertical-lines-in-r/

⇱ Plot Shaded Area between vertical lines in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Plot Shaded Area between vertical lines in R

Last Updated : 21 Aug, 2021

Plotting a shaded area between vertical lines means to put a vertical rectangle on a different color plot as compared to the rest of the plot area. We create this rectangle depending on the conditional values of the x-axis and represent the pivot area on the basis of characteristics of the data. This can be obtained using R and is described how in his article.

Function used

  • geom_rect() function is used to draw a rectangle

Syntax:

geom_rect(xmin, xmax, ymin, ymax, size, linetype, color, fill, alpha)

  • geom_vline() draws a vertical line at a specified position

Syntax:

geom_vline(xintercept, size, linetype, color, alpha)

Approach 1:

  • Create frame
  • Create plot
  • Now draw a rectangle to represent two vertical lines- first we will draw a hollow rectangle
  • Now add required color using fill parameter

Program 1: Draw two vertical files

Output: 

👁 Image

Program 2: Fill color between lines 

Output: 

👁 Image

Approach 2: 

  • Create frame
  • Draw two vertical lines
  • Fill color between them using a rectangle

Program 1: Drawing two lines 

Output: 

👁 Image

Program 2: Fill color between these lines  

Output: 

👁 Image


 

Comment
Article Tags:

Explore