LoslegenKostenlos loslegen

Adding points to a map

The maps created using plot_geo() are still plotly objects, so you can add additional layers as before. In this exercise, you will add points to a United States map representing the locations where President Trump held rallies for the 2018 midterm election. The dataset rallies2018 contains the date, city, state, latitude, longitude, and number of number of people who spoke.

Note that plotly has already been loaded for you.

Diese Übung ist Teil des Kurses

Interactive Data Visualization with plotly in R

Kurs anzeigen

Anleitung zur Übung

  • Use add_markers() to add points representing the rallies to the U.S. map. Be sure to map long to the x-axis, lat to the y-axis, and no.speakers to the size of the points.
  • Add the title "2018 Trump Rallies".
  • Restrict the scope of the map to the 'usa'.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Map President Trump's rallies in 2018
rallies2018 %>%
  plot_geo(locationmode = 'USA-states') %>%
  ___(
    ___, ___, ___,  
    hoverinfo = "text", text = ~paste(city, state, sep = ",")
  ) %>%
  ___(___ = ___, 
      geo = ___(___ = ___))
Code bearbeiten und ausführen