Introduction

The map of US population by state

library(plotly)

USpopu = read.csv("USpopstates.csv")
USpopu = USpopu %>% mutate(State = sub(".","",State)) %>% 
         mutate(hoverpop = paste(State,"<br>","Population:",Population))
                           

borders = list(color= toRGB("black"),width=2)
map_options = list(
                   scope="usa",
                   projection = list(type='albers usa'),
                   showlakes = TRUE,
                   lakecolor = toRGB("Light Blue")
                   ) 
                   
p = plot_ly(z = ~USpopu$Population,
        text = ~list(USpopu$hoverpop),
        # hoverinfo="text",
        locations = ~USpopu$Code,
        type="choropleth",
        locationmode='USA-states',
        color=~USpopu$Population,
                colors="Purples",
        marker = list(line=borders)) %>%
   colorbar(title = "Population") %>%
   plotly::layout(title='US Population <br>Estimates as of July 2017<br>(Hover for breakdown)', 
                  geo=map_options)

p

The map of age 18 and older population in US by state

library(plotly)

USpopu = USpopu %>% mutate(Popu18Pct = Popu18Pct*100) %>% 
         mutate(hoverpct = paste(State,"<br>","Percentage of Age 18 and older:",Popu18Pct,"%"))
                           

borders = list(color= toRGB("black"),width=2)
map_options = list(
                   scope="usa",
                   projection = list(type='albers usa'),
                   showlakes = TRUE,
                   lakecolor = toRGB("Light Blue")
                   ) 
                   
p = plot_ly(z = ~USpopu$Popu18Pct,
        text = ~list(USpopu$hoverpct),
        locations = ~USpopu$Code,
        type="choropleth",
        locationmode='USA-states',
        color=~USpopu$Popu18Pct,
                colors="Reds",
        marker = list(line=borders)) %>%
   colorbar(title = "Percentage") %>%
   plotly::layout(title='US Population Percentage of Age 18 and older<br>Estimates as of July 2017<br>(Hover for breakdown)', 
                  geo=map_options)

p