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 = TRUE
and set alandcolor
. - To make lakes distinct from landmasses, add the arguments
showlakes = TRUE
and 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.
This exercise is part of the course
Interactive Data Visualization with plotly in R
Exercise instructions
- Customize the appearance of your map from the previous exercise by defining the list
g
and passing it to thegeo
layout:- Set the landmass color with
"gray90"
. - Set the lake color with
"white"
. - Set the state (subunit) color with
"white"
.
- Set the landmass color with
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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 = ___)