USA state income in 1974

This site is created on Aug 12 2018

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
packageVersion('plotly')
## [1] '4.8.0'
library(datasets)
#?state # US state dataset to be used

# Create data frame
state_data <- data.frame(State_abb=state.abb, State_cencter=state.center, State_name=state.name, 
                        
                        state_income = as.vector(state.x77[,2]),
                        state_population=as.vector(state.x77[,1]),
                        state_frost = as.vector(state.x77[,7]),
                        state_area = as.vector(state.x77[,8]))
# Create hover text
state_data$hover <- with(state_data, paste(State_name,
                                           '<br>', "Average Income (1974):", state_income,
                                           '<br>', "Population (1975):", state_population,
                                           '<br>', "Freezing days (1931-1960):", state_frost,
                                           '<br>', "Area:", state_area))
# Make state borders red
borders <- list(color=toRGB("grey"), width=2)
# Set up some mapping options
map_options <- list(
    scope = 'usa',
    projection = list(type='Mercator'),
    showlake=TRUE,
    lakecolor = toRGB('white')
)

plot_ly(state_data, z=state_data$state_income, text=state_data$hover,
        locations=state_data$State_abb,
        type = 'choropleth', locationmode='USA-states',
        color = state_data$state_income, colors = 'Purples', marker = list(line=borders)) %>%
    colorbar(title= "PCI in USD") %>%
    layout(title = 'US State Facts: Per Capita Income (1974)', geo=map_options)