df_violin <- df_sina %>% 
  pivot_longer(cols = !c(1:2),
               names_to = "conditions",
               values_to = "abs")
df_bw_v <- df_sina[1:10, 1:8] %>% 
  pivot_longer(cols = !c(1:2),
               names_to = "conditions",
               values_to = "abs")

Violin

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin()

Jacob: ggplot creates a violin plot with specified categories of independent variables (“conditions” in this case) on the x-axis and a continuous scale of dependent variable (“abs” in this case) on the y-axis.

Violin Modification

Scale

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin(scale = "count") # "count" , "width"

Jacob: Default for geom_violin is “area”. Defining scales: area = area of each violin proportional to # of observations; count = with of violin proportional to # of observations; width = width of each violin is set to the maximum width. This means that “area” is the width of the graph alongside the height of the y-axis and is a function of the number of observations. “With” is the total width of the graph is set to the maximum number of values in the violin. “Count” is set where the total width of the violin is proportional to number of values in that violin y-axis.

Trim

df_violin %>% 
  ggplot(aes(x=abs, y=conditions))+
  geom_violin(trim = FALSE)#TRUE

Jacob: Default is “TRUE”. Defining trim: TRUE restricts violins to range of data (visually: cuts full violins only to range limits). FALSE releases violin restriction to data. Turning this off will cause the violin to extend past the range of the data and display inaccurate representations of your data. This representation is a prediction of the data outside of your range.

Quantiles

df_violin%>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin(draw_quantiles = c(0.25, 0.5, 0.75))
## Warning: The `draw_quantiles` argument of `geom_violin()` is deprecated as of ggplot2
## 4.0.0.
## ℹ Please use the `quantiles.linetype` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Jacob: Draw_quantiles requires a specified list. Off by default. Defining quantiles: Can be any form of quantile, listed in code is 0.25 for min to Q1, 0.5 for Q1 to median, 0.75 for Median to Q3, final section is default from Q3 to max. Any quantile can be made representative on this graph, but not all quantities. Quantities like average require a different solution.

Error

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin()+
  stat_summary(fun.data = "mean_sdl", geom = "errorbar", color = "red", width = 0.1)

Jacob Sum stats part of ggplot2, not Violin. Can be used with violin. Specify the value you are looking for. Defining summ stats values: create a function (fun) argument and describe the application you desire. For standard deviation, it is “fun.data = mean_se”. From there, you can specify the errorbar or point you want, the width (errorbar) or size (point) that you want, and the color of the added layer. For point, you can also change the shape.

##Mean

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin()+
  stat_summary(fun = mean, geom = "point", color = "red", size = 3, shape = 15)+
  stat_summary(fun.data = "mean_sdl", geom = "errorbar", color = "blue", width = 0.5)

Jacob: This graph is the point version of the functions above where the stat_summary argument was applied.

Violin and Boxplot

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin(aes(fill = conditions))+
  geom_boxplot(width = 0.1)

Jacob: geom_boxplot is ggplot2 package. Here we are just placing a thin (width = 0.1 times the normal size to fit in violins) boxplot. Defining geom_boxplot: look at B&W files (will link to Box and Whisker plot HTML in future) We are using this boxplot as another method of viewing the median, Q1, and Q3 of the violins, like was done in “quantiles” section. This allows us to visibly see the distribution of the data and shows numerical values that are important for understanding relative results of the tests.

Violin and Sina

#install.packages("ggforce")

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_violin()+
  geom_sina()

Jacob: Geom_sina is in ggforce package, not native to ggplot2. (Have to install new package) Defining sina: sina is plotted data in a violin shape. This allows us to see the distribution of number of data points in the same way that a violin does, and also clearly shows outliers in the data sets.

Sina

df_violin %>% 
  ggplot(aes(x=conditions, y=abs))+
  geom_sina()

Jacob: This graph is purely the sina graph from ggforce. You can change more about the point shape, color, size, and labeling (especially for outliers) using a similar method to B&W.