Get startedGet started for free

Tidying up the legend and some final tweaks

Time for some final tweaks and then to save your plot.

Every element in your plot is a target for tweaks. Is it the right color? Is it the right size? Does it have intuitive labels? Your goal is to emphasize the data and de-emphasise the non-data elements.

We've got some ideas for this plot. Let's tweak a few things.

This exercise is part of the course

Visualizing Geospatial Data in R

View Course

Exercise instructions

  • Make it clear what the color represents by adding title = "Median Income" and palette = "Greens" in the tm_fill() call, which will map income to a green color scale.
  • Add subtle borders to the tracts to make it more clear where their boundaries are by adding a tm_borders() layer with col = "grey60" and lwd = 0.5.
  • Make the neighborhood boundaries a little more important than tract boundaries by setting col = "grey40" and lwd = 2.
  • Add a data source credit using a tm_credits() call with first argument "Source: ACS 2014 5-year Estimates, \n accessed via acs package" and second argument position = c("right", "bottom").
  • Finally, save your plot as "nyc_income_map.png" using the tmap_save() function with arguments width = 4 and height = 7.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(tmap)

tm_shape(nyc_tracts_merge) +
  # Add title and change palette
  tm_fill(col = "estimate", 
          ___,
          ___) +
  # Add tm_borders()
  ___ +
  tm_shape(water) +
  tm_fill(col = "grey90") +
  tm_shape(manhat_hoods) +
  # Change col and lwd of neighborhood boundaries
  tm_borders() +
  tm_text(text = "name", size = 0.5) +
  # Add tm_credits()
  
  
        
# Save map as "nyc_income_map.png"
Edit and Run Code