undercoverindian
12/27/2017 - 12:23 AM

Using plotly to make graphs

Using plotly to make graphs

source('./scripts/buildMap.R')
LEAFLET

pal <- colorFactor(c("orange", "red"), domain = shootings$total.affected)

col_labels <- c(paste0(shootings$city, " - ", shootings$date, ". 
                       There was a total of ", shootings$killed, " individual(s)                           killed and ", shootings$injured, " individual(s) injured."))

map <- leaflet(data = shootings) %>% addTiles() %>%
              addCircleMarkers(~lng, ~lat, popup = ~as.character(col_labels), 
              radius = shootings$total.affected / 2, 
              color = ~pal(total.affected))
map


PLOTLY

g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB('gray'),
  countrycolor = toRGB('gray'),
  countrywidth = 0.5,
  subunitwidth = 0.5
)

plot_geo(shootings, lat = ~lat, lon = ~lng) %>%
  
  add_markers(
    text = ~paste(city, date, paste("Killed:", killed), paste("Injured:", injured),
    sep = "<br />"), color = ~total.affected, colors = 'Reds', 
    symbol = I("circle"), size = I(~total.affected), hoverinfo = "text") %>%
    colorbar(title = 'Number of individuals either injured or killed') %>%
    layout(title = 'Shootings in 2016', geo = g)
plot_ly(data, x = ~Bodywt, y = ~Brainwt, 

    type = 'scatter',         
    mode = 'text', 
    text = ~Primates, 
    textposition = 'middle right',         
    
    textfont = list(color = '#000000', size = 16)) %>%
    layout(title = 'Primates Brain and Body Weight',     
    
    xaxis = list(title = 'Body Weight (kg)',                          
    zeroline = TRUE,                           
    range = c(0, 250)),             
    yaxis = list(title = 'Brain Weight (g)',                           
    range = c(0,1400)))