import the library
library(ggplot2)
create a function to plot violin plot and passs the arguments from iris dataset also make trim false to get outliers along the density
plot_violin_plot <-function(data,continuous_var,group_var)
{
ggplot(data,aes_string(y=continuous_var,x=group_var,fill=group_var))+
geom_violin(trim=FALSE)+
labs(
title=(paste("violin plot on",continuous_var,"by",group_var)),
x=group_var,
y=continuous_var
)+
theme_minimal()
}
call function and plot the graph
plot_violin_plot(iris,"Sepal.Length","Species")
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.