ComeçarComece de graça

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.

Este exercício faz parte do curso

Building Dashboards with shinydashboard

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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
___
Editar e executar o código