#Add the included `sf` object with roads to the montereybay dataset
if(rayshader:::run_documentation()) {
#Create the water palette
water_palette = colorRampPalette(c("darkblue", "dodgerblue", "lightblue"))(200)
bathy_hs = height_shade(montereybay, texture = water_palette)
#Set label font
par(family = "Arial")
#We're plotting the polygon data here for counties around Monterey Bay. We'll first
#plot the county names at the polygon centroids.
bathy_hs %>%
add_shadow(lamb_shade(montereybay,zscale=50),0.3) %>%
add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow,
extent = attr(montereybay,"extent"),
heightmap = montereybay)) %>%
add_overlay(generate_label_overlay(labels=monterey_counties_sf,
color="black", point_size = 1, text_size = 1,
data_label_column = "NAME",
extent= attr(montereybay,"extent"), heightmap = montereybay,
seed=1)) %>%
plot_map()
}
if(rayshader:::run_documentation()) {
#It's hard to read these values, so we'll add a white halo.
bathy_hs %>%
add_shadow(lamb_shade(montereybay,zscale=50),0.3) %>%
add_overlay(generate_polygon_overlay(monterey_counties_sf, palette = rainbow,
extent = attr(montereybay,"extent"),
heightmap = montereybay)) %>%
add_overlay(generate_label_overlay(labels=monterey_counties_sf,
color="black", point_size = 1, text_size = 1,
data_label_column = "NAME",
extent= attr(montereybay,"extent"), heightmap = montereybay,
halo_color = "white", halo_expand = 3,
seed=1)) %>%
plot_map()
}
if(rayshader:::run_documentation()) {
#Plot the actual town locations, using the manual plotting interface instead of the `sf` object
montereybay %>%
height_shade() %>%
add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) %>%
add_shadow(lamb_shade(montereybay,zscale=50),0.3) %>%
add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME),
x=as.numeric(as.character(monterey_counties_sf$INTPTLON)),
y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)),
color="black", point_size = 1, text_size = 1,
extent= attr(montereybay,"extent"), heightmap = montereybay,
halo_color = "white", halo_expand = 3,
seed=1)) %>%
plot_map()
}
if(rayshader:::run_documentation()) {
#Adding a softer blurred halo
montereybay %>%
height_shade() %>%
add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) %>%
add_shadow(lamb_shade(montereybay,zscale=50),0.3) %>%
add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME),
x=as.numeric(as.character(monterey_counties_sf$INTPTLON)),
y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)),
color="black", point_size = 1, text_size = 1,
extent= attr(montereybay,"extent"), heightmap = montereybay,
halo_color = "white", halo_expand = 3, halo_blur=10,
seed=1)) %>%
plot_map()
}
if(rayshader:::run_documentation()) {
#Changing the seed changes the locations of the labels
montereybay %>%
height_shade() %>%
add_overlay(generate_altitude_overlay(bathy_hs, montereybay, 0, 0)) %>%
add_shadow(lamb_shade(montereybay,zscale=50),0.3) %>%
add_overlay(generate_label_overlay(labels=as.character(monterey_counties_sf$NAME),
x=as.numeric(as.character(monterey_counties_sf$INTPTLON)),
y=as.numeric(as.character(monterey_counties_sf$INTPTLAT)),
color="black", point_size = 1, text_size = 1,
extent= attr(montereybay,"extent"), heightmap = montereybay,
halo_color = "white", halo_expand = 3, halo_blur=10,
seed=2)) %>%
plot_map()
}
Run the code above in your browser using DataLab