0
$\begingroup$

This is my R script to draw the density plot:

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

Is there a way to plot three density plots (one for every species: setosa, virginica and versicolor) in the same graph?

$\endgroup$
1
  • $\begingroup$ try seaborns density plot $\endgroup$ Aug 11, 2022 at 22:00

1 Answer 1

1
$\begingroup$

For plotting I prefer to use the ggplot2 package since I find it easier to use and more versatile. Using this package you can easily plot multiple density plots:

library(ggplot2)

iris %>%
  ggplot(aes(x=Sepal.Length, colour=Species)) +
  geom_density()

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.