Course 9 - Week 3 project Plotly Map

Wellintton Perez
11/20/2019

This presentation I have included a map of the USA showing the distributions of students participating in Classroom, Inc.

Loading and Preparing the data for the plot

library(plotly)
data<-fread("dateset-latlon.csv",sep=",",stringsAsFactors = FALSE,nrows=-1)

top_5_states <- data[order(-data$count)][1:5]
labels <- c(paste(top_5_states$state,top_5_states$count,sep=": "))

state_count <- data.frame(state = state.abb[match(data$state,state.name)], count = as.vector(data$count))

state_count$hover <- with(state_count, paste(state, '<br>', "Students:", count))

borders <- list(color = toRGB("red"))

map_options <- list(
  scope = 'usa',
  projection = list(type = 'state usa'),
  showlakes = TRUE,
  lakecolor = toRGB('white'))

  gg<-plot_ly(z = ~state_count$count, text = ~state_count$hover, locations = ~state_count$state,
          type = 'choropleth', locationmode = 'USA-states',
          color = state_count$count, colors = 'Blues', marker = list(line = borders)) %>%
       layout(title = 'Classroom, Inc. Students', geo = map_options)

Classroom, Inc. Student distribution

The map shows the states where Classroom, Inc has affiliated with local schools to allow students to play the games.

  • Hover over the map to view the popup showing the total number of students per state.
Error in file(con, "rb") : cannot open the connection