Density Plots Using Lattice Package in R
The density plots are mainly used to visualize the distribution of continuous numeric variables. The densityplot() uses kernel density probability estimate to calculate the density probability of numeric variables. In R Programming, the density plot can be plotted using the densityplot() function which is present in the lattice package.
Syntax: densityplot(x,data, type, xlab, main)
- x – the column(s) where the density needs to be visualized
- data – data frame is specified here
- xlab – used to add an x-axis label to the plot
- main – used to add a title to the plot
In this article, we will be using the iris dataset. Firstly, we will plot the Simple Density Plot. Before that, install the lattice package using the below code.
We can also specify the particular points using parameters from and to. The output will be same as above but only between the points we have specified.
To plot the partitioned density plot as per the Species Category, follow the code given below.
We can also plot the Count Based Density Plot by specifying the type parameter as count.
Let’s see how to plot Customized Density Plot for iris dataset.
Please Login to comment...