1. Learn
  2. /
  3. Courses
  4. /
  5. Interactive Maps with leaflet in R

Connected

Exercise

addPolygon() Options

So far we have used the default appearance for addPolygons(). There are several more ways to customize the polygons.

The arguments to addPolygons() we will focus on are:

  • weight: the thickness of the boundary lines in pixels
  • color: the color of the polygons
  • label: the information to appear on hover
  • highlightOptions: options to highlight a polygon on hover
addPolygons(weight = 2,
           color = "red",
           label = ~paste0("Total Income: ", dollar(income)),
           highlight = highlightOptions(weight = 10,
                                       color = "blue",
                                       bringToFront = TRUE))

The high_inc SpatialPolygonsDataFrame you created in the previous exercise has been loaded for you.

Instructions

100 XP
  • Use the arguments of addPolygons() to map the high income zip codes in NC with:
    • A boundary thickness of 1 pixel,
    • Polygons that are colored with the nc_pal palette and are highlighted on hover, and
    • Labels that display the words "Mean Income:" followed by the mean income of the zip code.