Create Frequency Polygon using ggplot2
To create a basic frequency polygon in the R Language using the ggplot2 package, we use the geom_freqpoly() function. By default, ggplot2 uses 30 bins to create the frequency polygon. By reducing the number of bins, you can make the lines on the plot smoother.
Syntax: ggplot( df, aes(value)) + geom_freqpoly( bins )
where,
- df: determines the data frame to be visualized.
- value: determines the y-axis column name.
- bins: determines the smoothness of the plot.
Example:
Here, is a basic frequency polygon made using the ggplot2 package.
R
library (ggplot2) # make this example reproducible set.seed (0) # create data frame index<-1:40 y<- sample (5:40,40,replace= TRUE ) df <- data.frame ( index, y ) # create frequency polygon using geom_freqpoly() # function ggplot (df, aes (y)) + geom_freqpoly (bins=10) |
Output:
How to Create a Frequency Polygon in R?
In this article, we will discuss how to create a Frequency Polygon in the R Programming Language.
Frequency polygons are the plots of the values in a data frame to visualize the shape of the distribution of the values. It helps us in comparing different data frames and visualizing the cumulative frequency distribution of the data frames. The frequency polygon indicates the number of occurrences for each distinct class in the data frame.
Contact Us