library(ggplot2)
library(plotly)
library(dplyr)
library(readr)

setwd("~/R/Machine_Learning")

states <- read_csv("states.csv")
minwage_df <- read_csv("Minimum Wage Data.csv") %>%
  inner_join(states, by.x = State, by.y = State) %>%
  select(Year,State,Code,Wage=Low.Value) %>%
  mutate(hover = paste0(State,"\n$",Wage))

fontStyle = list(
  family = "DM Sans",
  size = 15,
  color = "black"
)

label = list(
  bgcolor = "#EEEEEE",
  font = fontStyle
)

minwage_graph = plot_geo(minwage_df,
                          locationmode = 'USA-states',
                          frame = ~Year) %>%
  add_trace(locations = ~Code,
            z = ~Wage,
            zmin = 0,
            zmax = max(minwage_df$Wage),
            color = ~Wage,
            colorscale = 'Electric',
            text = ~hover,
            hoverinfo = 'text') %>%
  layout(geo = list(scope='usa'), #europe world
         font = list(family = "DM Sans")) %>%
  style(hoverlabel = label) %>%
  colorbar(tickprefix = "$")

minwage_graph