Read in the data

# Import .csv 
library(readr)
coffee_df <- read_csv("coffee.csv")
# head(coffee_df)
# Load libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ purrr     1.0.1
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)

Plot 1

bxplot <- ggplot(data = coffee_df) +
  geom_boxplot(aes(x=avg_rating, y=hhincome, group=1), color="black",fill="white")+
  scale_x_discrete(name ="Average Rating", 
                    limits=c("1","2","3","4","5"))

plotly::ggplotly(bxplot)

Plot 2

bxplot2 <- ggplot(data = coffee_df) +
  geom_boxplot(aes(x=avg_rating, y=hhincome, group=1), color="black",fill="white")+
  scale_x_discrete(name ="Average Rating", 
                    limits=c("1","2","3","4","5"))+
  facet_wrap(~county)

plotly::ggplotly(bxplot2)

Plot 3

library("RColorBrewer")
myPalette <- colorRampPalette(rev(brewer.pal(11, "RdYlBu")))
sc <- scale_colour_gradientn(colours = myPalette(100), limits=c(0, 1))
# Code Reference:
# https://stackoverflow.com/questions/21537782/how-to-set-fixed-continuous-colour-values-in-ggplot2

ggplot(data = coffee_df, 
       aes(x=review_count_log, y=hhincome, color=pct_white) 
       )+
  geom_point(alpha=0.7, size=3)+
  sc+
  facet_wrap(~county)+
  labs(color='Proportion of residences \n who self-identified as white',
       x="review count logged",
       y="median annual household income($)")+ 
  theme(legend.title = element_text(size = 8))  

Plot 4

fig1 <- ggplot(data = coffee_df) +
  geom_point(mapping = aes(x=review_count_log, y=hhincome, 
                           color=county))

fig2 <- ggplot(data = coffee_df) +
  geom_point(mapping = aes(x=review_count, y=rating, 
                           alpha=price, #<<
                           size=price)) #<<
coffee_p4 <- coffee_df %>% 
  select(review_count_log, pct_pov_log, hhincome, pct_white, race.tot, county)
longer_data <- coffee_p4 %>%
  pivot_longer(cols=c(pct_pov_log, hhincome, pct_white, race.tot), 
               names_to = "y", 
               values_to = "points")
# Code Reference:
# https://cameronpatrick.com/post/2019/11/plotting-multiple-variables-ggplot2-tidyr/
coffee_p4 %>%
  pivot_longer(cols=c(pct_pov_log, hhincome, pct_white, race.tot), 
               names_to = "y", 
               values_to = "points") %>%
  ggplot(aes(x=review_count_log, y=points, color=county)) +
  geom_point(size = 0.8)+
  geom_smooth(mapping = aes(x=review_count_log, y=points, color=county), 
              method = "lm", se=F)+
  facet_wrap(~y, 
             scales = "free",
             labeller = labeller(y = 
                                   c("hhincome" = "Median Annual Household Income($)",
                                     "pct_pov_log" = "Percent Residents under Poverty",
                                     "pct_white" = "Percent White Resident",
                                     "race.tot" = "Total Population")))+
  labs(x="Review Count Logged",
       y="",
       color="County")
## `geom_smooth()` using formula = 'y ~ x'