Geo layout
In the previous exercise you saw the default settings for the geo layout in plotly, but this it is quite easy to customize by specifying additional arguments in the list passed to geo in layout().
In this exercise you will explore a few useful options outlined below:
- To change the color of the landmass, add the arguments
showland = TRUEand set alandcolor. - To make lakes distinct from landmasses, add the arguments
showlakes = TRUEand set alakecolor. - To display states/provinces, set
showsubunit = TRUE, and the setsubunitcolor. - To display countries, set
showcountries = TRUE, and the setcountrycolor.
Note that you must use the toRGB() function in order to pass R colors to the geo layout.
plotly has already been loaded for you.
Diese Übung ist Teil des Kurses
Interactive Data Visualization with plotly in R
Anleitung zur Übung
- Customize the appearance of your map from the previous exercise by defining the list
gand passing it to thegeolayout:- Set the landmass color with
"gray90". - Set the lake color with
"white". - Set the state (subunit) color with
"white".
- Set the landmass color with
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Customize the geo layout
g <- list(scope = 'usa',
showland = ___, landcolor = ___,
showlakes = ___, lakecolor = ___,
showsubunit = ___, subunitcolor = ___)
# Apply the geo layout to the map
rallies2018 %>%
plot_geo(locationmode = 'USA-states') %>%
add_markers(
x = ~long, y = ~lat, size = ~no.speakers,
hoverinfo = "text", text = ~paste(city, state, sep = ",")
) %>%
layout(title = "2018 Trump Rallies", geo = ___)