The purpose of a violin plot:
It is used to visualize the distribution of numerical data.
library(ggplot2)
Sheff_temp <- read.csv("Sheffield_max_temp_data.csv", header = FALSE)
colnames (Sheff_temp) <- c ("Year", "Month", "Max_temp")
Sheff_temp_noNA <- na.omit(Sheff_temp)
attach(Sheff_temp_noNA)
ggplot (Sheff_temp_noNA,
aes (x = factor (Month, labels = month.abb),
y = Max_temp, fill = factor (Month)
) ##### Maps the month to the x-axis,
##### mean temperature to the y-axis,
##### and uses the fill aesthetic for different months.
)+
geom_violin (trim = FALSE, alpha = 0.8) + ### Creates a violin plot.
### trim: controls whether to trim the width of the violin
### alpha value to control the transparency of the violins according to your preferences
### higher value of alpha -> less transparent
scale_x_discrete(name = "Month") + ### Sets the axis labels.
scale_y_continuous(name = "Mean Temperature") +
ggtitle("Violin plot of Monthly Mean Temperature of Sheffield")+
### Gives the plot title.
theme_minimal()+
### Sets the plot theme to a minimal style.
theme(panel.background = element_rect(fill = "pink"))

### Sets the background color of the plot to pink
detach(Sheff_temp_noNA)