'Density plot on Iris dataset with R

I want to plot a density plot of my dataset. This is my code:

    data <- iris
    plot(density(data$Sepal.Length), 
    main="Density Plot", ylab="Frequency",
    sub=paste("Skewness:", round(e1071::skewness(data$Sepal.Length), 2)))  

My goal is to set up a plot function to select only virginica data. Is it possible?



Solution 1:[1]

The solution can be data <- iris

data <- data %>% filter(data$Species == "virginica")
plot(density(data$Sepal.Length), 
     main="Density Plot", ylab="Frequency",
     sub=paste("Skewness:", round(e1071::skewness(data$Sepal.Length), 2))) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Inuraghe