CommencerCommencer gratuitement

sf plots with plot()

As you have seen, sf objects can be plotted using the base R plot() function. The first plot will allow you to set up the base for the map, and subsequent layers can be added using plot().

In the following, there are four sf objects stored as:

  • london_poly
  • london_loop
  • london_capital
  • num_listings

Complete the code below to obtain a geospatial map using plot() to piece sf objects together. Use st_geometry() to ensure that all objects are indeed sf objects when plotted.

The sf and tidyverse libraries have been loaded.

Cet exercice fait partie du cours

Building Dashboards with shinydashboard

Afficher le cours

Instructions

  • Plot the first layer which is a multipolygon called london_poly.
  • Plot london_loop and color it purple.
  • Plot london_capital and color it green.
  • Add red markers for each point in num_listings.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Plot the first layer which is a multipolygon
___(___(london_poly), 
     col = sf.colors(length(london_poly$Name), 
                     categorical = TRUE), 
     axes=TRUE, border=grey(0.2, 0.5))
# Plot london_loop and color it purple
___(___(london_loop), add=___, col=___)
# Plot london_capital and color it green
___
# Add red markers for each point in num_listings
___
Modifier et exécuter le code