## -----------------------------------------------------------------------------
#| eval: false
# install.packages("ggplot2") # "downloading the app", do this once


## -----------------------------------------------------------------------------
#| eval: false
# library(ggplot2) # "opening the app", do this every time


## -----------------------------------------------------------------------------
#| eval: false
# ggplot(data = dataset,           # step 1: set your data
#        aes(x = x_var, y = y_var) # step 2: define aesthetics
#        ) +
#   geom_boxplot() +                 # step 3: add geometries
#   geom_bar() +
#   geom_histogram()


## -----------------------------------------------------------------------------
# code to get you started!
library(ggplot2)
tips <- read.delim('https://raw.githubusercontent.com/IowaBiostat/data-sets/main/tips/tips.txt')


## -----------------------------------------------------------------------------
ggplot(tips, aes(x = TotBill)) + 
  geom_histogram()


## -----------------------------------------------------------------------------
ggplot(tips, aes(x = Day, y = TotBill)) +
  geom_boxplot() 


## -----------------------------------------------------------------------------
ggplot(tips, aes(x = Day, y = TotBill)) +
  geom_boxplot() +
  facet_wrap(~Sex) 


## -----------------------------------------------------------------------------
# code to read in the data
lister <- read.delim('https://github.com/IowaBiostat/data-sets/raw/main/lister/lister.txt')

# construct the plot
ggplot(lister, aes(x = Group)) +
  geom_bar()


## -----------------------------------------------------------------------------
ggplot(lister, aes(x = Outcome, fill = Group)) +
  geom_bar(position = "dodge")


## -----------------------------------------------------------------------------
#| eval: false

# # look up xtabs
# ?xtabs

## -----------------------------------------------------------------------------
# Use xtabs to count the frequencies of Outcome within each Group
lister_table <- xtabs(~ Group + Outcome, data = lister)

# Print the table to the console
lister_table

