# scratch for tuesday, 9/2
# EDA on the storms data

# storms plot
# use as_factor in x-assignment to get labels back
storms |> ggplot(aes(x=as_factor(month),y=pressure)) + geom_boxplot()

# lat vs year
storms |> ggplot(aes(x=year,y=lat)) + geom_point()

# visualize the distribution of latitudes
storms |> ggplot(aes(x=lat)) + geom_histogram(binwidth = 1)

storms |> ggplot(aes(x=lat)) + geom_histogram(binwidth = 1) + 
  scale_x_continuous(
    breaks=seq(min(storms$lat), max(storms$lat), by = 2)
    )

# visualize latitudes & status
storms |> ggplot(aes(x=lat,fill=status)) + geom_histogram(binwidth = 1) + 
  scale_x_continuous(breaks=seq(min(storms$lat), max(storms$lat), by = 2))

# how does lat vary within status?
storms |> ggplot(aes(x=status,y=lat)) + geom_boxplot()

# deal with crowded labels
storms |> ggplot(aes(x=status,y=lat)) + geom_boxplot() + 
  scale_x_discrete(guide = guide_axis(n.dodge = 2))

# now reorder
storms |> ggplot(aes(x=reorder(status,lat),y=lat)) + geom_boxplot() + 
  scale_x_discrete(guide = guide_axis(n.dodge = 2))

# use the previous to explore other numerical distributions over the categorical status
# what distinguishes status? 
storms |> ggplot(aes(x=reorder(status,pressure),y=pressure)) + geom_boxplot() + 
  scale_x_discrete(guide = guide_axis(n.dodge = 2))

# compare stress & happy in atus data
ggplot(filter(data,SCSTRESS<90,SCHAPPY<50),aes(x=SCHAPPY,group=SCSTRESS)) + 
  geom_bar(aes(fill=haven::as_factor(SCSTRESS)))

# again, using new ideas
filter(data,SCHAPPY < 90, SCSTRESS < 90) |> group_by(SCHAPPY,SCSTRESS) |> summarise(n=n()) -> df
ggplot(df,aes(x=SCHAPPY,y=SCSTRESS)) + geom_tile(aes(fill=n))

# ------------------------------- #
# grouping (we're not there yet)
storms |> group_by(month,status) |> summarize(n=n()) -> df
df |> ggplot(aes(x=as_factor(month), y=status)) + geom_tile(aes(fill=n))
