Table of Contents
A frequency polygon in R is a graphical representation of the frequency distribution of a dataset. It displays the frequency of each data point or group of data points along a continuous line, providing a visual representation of the distribution’s shape. To create a frequency polygon in R, one can use the built-in function “freqpoly” from the “lattice” package. This function takes in the data and automatically calculates the frequency and plots the polygon. Additional customization options such as labeling axes and adding a title can be done using the “plot” function. By creating a frequency polygon in R, one can easily analyze and compare the distribution of data, making it a useful tool for data analysis.
Create a Frequency Polygon in R
A frequency polygon is a type of chart that helps you visualize the distribution of values in a dataset.
You can use the following syntax to create a frequency polygon using the data visualization package in R:
library(ggplot2) ggplot(df, aes(value)) + geom_freqpoly()
The following examples show how to use this syntax in practice.
Example 1: Basic Frequency Polygon
The following code shows how to create a basic frequency polygon for a dataset:
library(ggplot2) #make this example reproducible set.seed(0) #create data frame df <- data.frame(index=1:100, value=rnorm(100, mean=50, sd=10)) #create frequency polygon ggplot(df, aes(value)) + geom_freqpoly()

Example 2: Frequency Polygon with Custom Bins
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. For example, the following code creates a frequency polygon using 10 bins:
library(ggplot2) #make this example reproducible set.seed(0) #create data frame df <- data.frame(index=1:100, value=rnorm(100, mean=50, sd=10)) #create frequency polygon ggplot(df, aes(value)) + geom_freqpoly(bins=10)

Example 3: Frequency Polygon with Fill Color
If you’d like to fill in the frequency polygon with a certain color, you’ll need to instead use the geom_area() function as follows:
library(ggplot2) #make this example reproducible set.seed(0) #create data frame df <- data.frame(index=1:100, value=rnorm(100, mean=50, sd=10)) #create frequency polygon filled with custom color ggplot(df, aes(value)) + geom_area(aes(y=..count..), bins=10, stat='bin', fill='steelblue')

Cite this article
stats writer (2024). How can I create a frequency polygon in R?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-create-a-frequency-polygon-in-r/
stats writer. "How can I create a frequency polygon in R?." PSYCHOLOGICAL SCALES, 6 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-create-a-frequency-polygon-in-r/.
stats writer. "How can I create a frequency polygon in R?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-create-a-frequency-polygon-in-r/.
stats writer (2024) 'How can I create a frequency polygon in R?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-create-a-frequency-polygon-in-r/.
[1] stats writer, "How can I create a frequency polygon in R?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can I create a frequency polygon in R?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
