#Load libraries for plotting
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

#iris2 modified version of iris
iris2 <- iris %>%
  #filter any petail length exactly 3.5
  filter(Petal.Length != 3.5) %>%
  # calculate a new column based on the given ratio at the bottom
  mutate(ratio = Sepal.Length / Sepal.Width)

#multi-layered plot creation at the bottom
ggplot(iris2, aes(Species, ratio, fill = Species)) +
  #density/shape of the data
  geom_violin() +
  #median and quartiles of the data
  geom_boxplot() +
  #allow individual points to be seen
  geom_jitter() +
  labs(
    #title for graph
    title = "Sepal Ratio by Species",
    #caption for graph
    caption = paste("Excluded Petal.Length of 3.5")
  )

#Base r plot for economics_long
plot(economics_long$date, economics_long$value,
     main = "Value Over Time",
     xlab = "Date", ylab = "Value")

#ggplot version plot with different variables
ggplot(economics_long, aes(x = date, y = value, color = variable)) +
  #create lineplot
  geom_line() +
  labs(
    #title of graph
    title = "Economic Over Time",
    #subtitle of graph
    subtitle = "Variables",
    #x-axis of graph
    x = "Date",
    #y-axis of graph
    y = "Value",
    #caption of graph
    caption = "Economics dataset"
  )

#same plot as before, but zoomed in
ggplot(economics_long, aes(x = date, y = value, color = variable)) +
  #create line
  geom_line() +
  #zoom in by limiting the view without deleting anything.
  coord_cartesian(ylim = c(0, 10000)) +
  #make graph minimal and clean
  theme_minimal()

#get penguin dataset
library(palmerpenguins)
## 
## Attaching package: 'palmerpenguins'
## The following objects are masked from 'package:datasets':
## 
##     penguins, penguins_raw
#modified version of penguins
penguins2 <- penguins %>%
  #filter out any missing weight
  filter(!is.na(body_mass_g))

#ggplot for plotting density
ggplot(penguins2, aes(x = body_mass_g, fill = species)) +
  #make the transparency 0.7 not too solid
  geom_density(alpha = 0.7) +
  labs(
    #title of graph
    title = "Body Mass by Species",
    #x-axis of graph
    x = "Body Mass",
    #y-axis of graph
    y = "Density"
  )

library(ggplot2)

#make a proportional bar 
ggplot(diamonds, aes(x = color, fill = cut)) +
  #gives all bar ratio and fills it
  geom_bar(position = "fill") +
  #colorblind friendly
  scale_fill_viridis_d() +
  labs(
    #title of graph
    title = "Diamond Cuts by Color",
    #x-axis of graph
    x = "Diamond Color",
    #y-axis of grpah
    y = "Proportion",
    #ratio by cut
    fill = "Cut",
    #caption of graph
    caption = "Diamonds dataset"
  )

#grouped bar for side by side for raw count
ggplot(diamonds, aes(x = color, fill = cut)) +
  #place cut bars next to each other
  geom_bar(position = "dodge") +
  #colorblind friendly
  scale_fill_viridis_d() +
  labs(
     #title of graph
    title = "Diamond Cuts by Color",
    #x-axis of graph
    x = "Diamond Color",
    #y-axis of graph
    y = "Count",
    #ratio by cut
    fill = "Cut",
    #caption of graph
    caption = "Diamonds dataset"
  )