Add Color Between Two Points of Kernel Density Plot in R Programming - Using with() Function Last Updated : 19 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report plot() and with() functions are used to draw and add color between a particular area of two points of Kernel Density Plot in R Language. Draw a Kernel Density plot plot() function in R Language is used to draw a Kerner Density Plot Syntax: plot(dens_x) Parameters: dens_x: Default plot of density. Returns: Kernel density plot r # Create example data set.seed(72500) x <- rnorm(800) dens_x <- density(x) plot(dens_x) Output: Adding Color to Plot with() function is used to add color between two points of the graph. Syntax: with(dens_x, polygon(x = c(x[c 1="x_low:x_high," 2="x_high)" language="(x_low,"][/c]), y = c(0, y[x_low:x_high], 0), col = " ")) Parameters: dens_x: Default plot of density. x_low, x_high: lower limit and upper limit of colored area col: Name of color Returns: Color plot between to particular plots with specified color. r # color the plot set.seed(72500) x <- rnorm(800) dens_x <- density(x) plot(dens_x) x_low <- min(which(dens_x$x >= - 0.5)) # Define lower limit of colored area x_high <- max(which(dens_x$x < 1)) # Define upper limit of colored area with(dens_x, # Add color between two limits polygon(x = c(x[c(x_low, x_low:x_high, x_high)]), y = c(0, y[x_low:x_high], 0), col = "darkgreen")) Output: Comment More infoAdvertise with us Next Article Draw Line Segments between Particular Points in R Programming - segments() Function K kaurbal1698 Follow Improve Article Tags : R Language R-plots R Functions Similar Reads Addition of more points to a Plot in R Programming - points() Function points() function in R Language is used to add a group of points of specified shapes, size and color to an existing plot. Syntax: points(x, y, cex, pch, col) Parameters: x, y: Vector of coordinates cex: size of points pch: shape of points col: color of points Sample Scatter Plot: Python3 1== # R pro 2 min read Draw Line Segments between Particular Points in R Programming - segments() Function segment() function in R Language is used to draw a line segment between to particular points. Syntax: segments(x0, y0, x1, y1) Parameters: x, y: coordinates to draw a line segment between provided points. Returns: a line segment between given points Example 1: To draw a single line segment r # Creat 2 min read Addition of Lines to a Plot in R Programming - lines() Function In R, the lines() function is called to add on top of already existing plot. This is particularly helpful when you want to add more lines, such as trend lines, regression lines, or special lines, on a plot. The lines() function allows flexibility in line color, line width, and line type, with multip 3 min read Draw a Polygon between specified points in R Programming - polygon() Function polygon() function in R Language is used to plot a polygon between specified points in an existing plot.Syntax: polygon(x_coordinates, y_coordinates) Parameters : x_coordinates, y_coordinates: x, y coordinates of plot to draw polygon Returns: a polygon in a given plotExample 1: Draw a 4 Sided Polygo 2 min read Compute the Cumulative Poisson Density in R Programming - ppois() Function ppois() function in R Language is used to compute the cumulative density function for Poisson distribution. Syntax: ppois(vec, lambda) Parameters: vec: Sequence of integer values lambda: Average number of events per interval Example 1: Python3 1== # R program to compute # Cumulative Poisson Density 1 min read Plotting of Data using Generic plots in R Programming - plot() Function In this article, we will discuss how we plot data using Generic plots in R Programming Language using plot() Function. plot functionplot() function in R Programming Language is defined as a generic function for plotting. It can be used to create basic graphs of a different type. Syntax: plot(x, y, t 5 min read Like