packages <- c("ggplot2", "readr", "tidyverse", "dplyr", "ggpubr", "see", "rmarkdown", "knitr", "tinytex")

check_install_packages <- function(pkg){
  if (!require(pkg, character.only = TRUE)) {
    install.packages(pkg, dependencies = TRUE)
    library(pkg, character.only = TRUE)
  }
}

sapply(packages, check_install_packages)
## $ggplot2
## NULL
## 
## $readr
## NULL
## 
## $tidyverse
## NULL
## 
## $dplyr
## NULL
## 
## $ggpubr
## NULL
## 
## $see
## NULL
## 
## $rmarkdown
## NULL
## 
## $knitr
## NULL
## 
## $tinytex
## NULL

Graphic Assignment 2

## Replica Violin and Half-Violin Plot

CAM <- read.csv("C:/Users/seank/Downloads/R_Coding_Course/Violin_Plot_Data.csv")

data_long <- CAM %>%
  pivot_longer(
    cols = starts_with("Repeat"),
    names_to = "Repeat", 
    values_to = "values")

#head(data_long, 40)

ggplot(data_long, aes(x = F1Performance, y = values))+
  geom_jitter(aes(color = F1Performance), alpha = 0.8, size = 5, 
              position = position_jitter(width = 0.1))+
  scale_color_manual(values = c("darkorchid4", "darkorange1"))+
  geom_violin(aes(fill = F1Performance), alpha = 0.5, size = 2, 
              draw_quantiles = c("0.25", "0.50", "0.75"), quantile.size = 2)+
  stat_summary(fun = median, geom = "point", shape = 21, size = 3, fill = "white", color = "black",
               stroke = 1.5)+
  scale_fill_manual(values = c("darkorchid4", "darkorange1"))+
  coord_flip()+
  theme_minimal()+
  theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), 
        legend.position = "none",
        axis.line.x.bottom = element_line(color = "black", size = 1.5), 
        plot.title = element_text(hjust = 0.5, face="bold"), 
        panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank(), 
        panel.grid.major.x = element_line(colour = "grey", linewidth = 1.5, linetype = "dashed"))+
  geom_text(aes(x = "SVMWithGradCAMMaps", label = "SVM + GRAD-CAM++", y = 0.64), vjust = -4.5, 
            color = "darkorange1", size = 4.5)+
   geom_text(aes(x = "SVMWithDeepShapMaps", label = "SVM + Deep SHAP", y = 0.59), vjust = -4.5, 
            color = "darkorchid4", size = 4.5)+
  scale_y_continuous(limits = c(0.56, 0.74), 
                     breaks = seq(0.56, 0.74, by = 0.02), 
                     labels = seq(0.56, 0.74, by = 0.02))+
  labs(title = "Fig. 7. Grad-CAM++ saliency maps capture unique predicitve information", y = "F1"
       )

ggplot(data_long, aes(x = F1Performance, y = values))+
  geom_jitter(aes(color = F1Performance), alpha = 0.8, size = 5, 
              position = position_jitter(width = 0.1))+
  scale_color_manual(values = c("darkorchid4", "darkorange1"))+
  geom_violinhalf(aes(fill = F1Performance), alpha = 0.5, size = 2, 
              draw_quantiles = c("0.25", "0.50", "0.75"), quantile.size = 2)+
  stat_summary(fun = median, geom = "point", shape = 21, size = 3, fill = "white", color = "black",
               stroke = 1.5)+
  scale_fill_manual(values = c("darkorchid4", "darkorange1"))+
  coord_flip()+
  theme_minimal()+
  theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), 
        legend.position = "none",
        axis.line.x.bottom = element_line(color = "black", size = 1.5), 
        plot.title = element_text(hjust = 0.5, face="bold"), 
        panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank(), 
        panel.grid.major.x = element_line(colour = "grey", linewidth = 1.5, linetype = "dashed"))+
  geom_text(aes(x = "SVMWithGradCAMMaps", label = "SVM + GRAD-CAM++", y = 0.64), vjust = -4.5, 
            color = "darkorange1", size = 4.5)+
   geom_text(aes(x = "SVMWithDeepShapMaps", label = "SVM + Deep SHAP", y = 0.59), vjust = -4.5, 
            color = "darkorchid4", size = 4.5)+
  scale_y_continuous(limits = c(0.56, 0.74), 
                     breaks = seq(0.56, 0.74, by = 0.02), 
                     labels = seq(0.56, 0.74, by = 0.02))+
  labs(title = "Fig. 7. Grad-CAM++ saliency maps capture unique predicitve information", y = "F1"
       )

Before Flipping it seems like quantile.size isn’t doing anything but size is making the lines thicker. Then when doing the jitter points I had to run the code multiple time to get it so my points looked like yours. Is there a way to make it look like yours from the beginning or is it random.

## Revised Replica Violin Plot with Box Plot
ggplot(data_long, aes(x = F1Performance, y = values))+
  geom_violin(aes(fill = F1Performance), alpha = 0.5, size = 1)+
  scale_fill_manual(values = c("#298c8c", "#800074"))+
  geom_boxplot(width = 0.3, color = "black", fill = "NA", size = 1)+
  coord_flip()+
  theme_minimal()+
  theme(axis.title.y = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), 
        legend.position = "none",
        axis.line.x.bottom = element_line(color = "black", size = 1.5), 
        plot.title = element_text(hjust = 0.5, face="bold"), 
        panel.grid.major.y = element_blank(), panel.grid.minor.x = element_blank(), 
        panel.grid.major.x = element_line(colour = "grey", linewidth = 1.5, linetype = "dashed"))+
  geom_text(aes(x = "SVMWithGradCAMMaps", label = "SVM + GRAD-CAM++", y = 0.64), vjust = -5.8, color = "#800074", size = 4.5)+
   geom_text(aes(x = "SVMWithDeepShapMaps", label = "SVM + Deep SHAP", y = 0.59), vjust = -5.2, color = "#298c8c", size = 4.5)+
  scale_y_continuous(limits = c(0.56, 0.74), 
                     breaks = seq(0.56, 0.74, by = 0.02), 
                     labels = seq(0.56, 0.74, by = 0.02))+
  labs(title = "Fig. 7. Grad-CAM++ saliency maps capture unique predicitve information", y = "F1"
       )


Graphic Assignment 1

Discussion:

What are the variables available? The type of felony they were arrested for and the percent urban population for each state

How is each variable defined or calculated? Murder, Assault, and Rape are all arrests per 100,000 and Urban population is a percentage

Is each one numerical or categorical? they are all numerical