@DanaWestley Per your original email, and this might apply to others
You couldn't get ggplotly() to work using map_data("world"). It was timing out for me as well. I think this is just because the geodatabase is so large for all the countries' borders. Instead, you can use plot_ly() to build the map. See the example here.
plot_ly() requires you to identify each country using a three-letter abbreviation. If your data frame doesn't already include this column, use countrycode() from the countrycode library to add it to the data frame, then use that new code variable to link the quantitative variable to the correct country in the map.
So for you @DanaWestley, add this code after you import data:
library(countrycode) # install this package before running the code
data %>%
mutate(code = countrycode(Country, "country.name", "iso3c")) %>%
plot_geo() %>%
add_trace(z = ~ TotalFert2015, locations = ~ code)
And you should generate a basic choropleth with plotly. From here you can customize it to add hover text information and other necessary elements. See the plotly documentation for more details.
@DanaWestley Per your original email, and this might apply to others
You couldn't get
ggplotly()
to work usingmap_data("world")
. It was timing out for me as well. I think this is just because the geodatabase is so large for all the countries' borders. Instead, you can useplot_ly()
to build the map. See the example here.plot_ly()
requires you to identify each country using a three-letter abbreviation. If your data frame doesn't already include this column, usecountrycode()
from thecountrycode
library to add it to the data frame, then use that new code variable to link the quantitative variable to the correct country in the map.So for you @DanaWestley, add this code after you import
data
:And you should generate a basic choropleth with plotly. From here you can customize it to add hover text information and other necessary elements. See the plotly documentation for more details.