library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
myurl <- "https://www2.census.gov/govs/statetax/15staxcd.txt"
mydestfile <- "15staxcd.txt"
download.file(myurl, destfile = mydestfile)
mydata <- read.table(mydestfile, header=TRUE, sep=",")
alcbev_taxes <- mydata[3,c(2:8, 10:52)]
# Create data frame
state_tax <- data.frame(State = names(alcbev_taxes), 
                        Taxes = t(alcbev_taxes))
names(state_tax)<-c("State", "Taxes")

# Create hover text
state_tax$hover <- with(state_tax, paste(State, '<br>', "Taxes:", Taxes))
borders <- list(color = toRGB("red"))
# Set up some mapping options
map_options <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showlakes = TRUE,
  lakecolor = toRGB('white')
)
plot_ly(z = state_tax$Taxes, text = state_tax$hover, locations = state_tax$State, 
        type = 'choropleth', locationmode = 'USA-states', 
        color = state_tax$Taxes, colors = 'Blues', marker = list(line = borders)) %>%
  layout(title = 'Alcoholic Beverages Sales Tax per State, 2015 <br>(US Census Bureau)', 
         geo = map_options)
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.