library(rjson)
library(plotly)
url <- 'https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json'
counties <- rjson::fromJSON(file=url)
url2<- "https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv"
df <- read.csv(url2, colClasses=c(fips="character"))
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choroplethmapbox",
geojson=counties,
locations=df$fips,
z=df$unemp,
colorscale="Viridis",
zmin=0,
zmax=12,
marker=list(line=list(
width=0),
opacity=0.5
)
)
fig <- fig %>% layout(
mapbox=list(
style="carto-positron",
zoom =2,
center=list(lon= -95.71, lat=37.09))
)
fig#Maps
library(plotly)
library(rjson)
url <- 'https://raw.githubusercontent.com/plotly/datasets/master/election.geojson'
geojson <- rjson::fromJSON(file=url)
url2<- "https://raw.githubusercontent.com/plotly/datasets/master/election.csv"
df <- read.csv(url2)
g <- list(
fitbounds = "locations",
visible = FALSE
)
fig <- plot_ly()
fig <- fig %>% add_trace(
type="choroplethmapbox",
geojson=geojson,
locations=df$district,
z=df$Bergeron,
colorscale="Viridis",
featureidkey="properties.district"
)
fig <- fig %>% colorbar(title = "Bergeron Votes")
fig <- fig %>% layout(
mapbox=list(
style="carto-positron",
zoom =9,
center=list(lon=-73.7073, lat=45.5517))
)
figlibrary(mapboxer)
library("tidyverse")library(mapboxer)
# Create a source
motor_vehicle_collisions_nyc %>%
dplyr::mutate(color = ifelse(injured > 0, "red", "yellow")) %>%
as_mapbox_source(lng = "lng", lat = "lat") %>%
# Setup a map with the default source above
mapboxer(
center = c(-73.9165, 40.7114),
zoom = 10
) %>%
# Add a navigation control
add_navigation_control() %>%
# Add a layer styling the data of the default source
add_circle_layer(
circle_color = c("get", "color"),
circle_radius = 3,
# Use a mustache template to add popups to the layer
popup = "Number of persons injured: {{injured}}"
)library(plotly)
us_cities = read.csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
fig <- us_cities
fig <- fig %>%
plot_ly(
lat = ~lat,
lon = ~lon,
marker = list(color = "fuchsia"),
type = 'scattermapbox',
hovertext = us_cities[,"City"])
fig <- fig %>%
layout(
mapbox = list(
style = 'open-street-map',
zoom =2.5,
center = list(lon = -88, lat = 34)))
fig