0

I am trying to create a map showing the neighborhoods of Manhattan with a number referring to each neighborhood.

I want to associate a number for each of the 29 neighborhoods and display that number at the centroid of each polygon. I then want the legend to display the numbers and the neighborhood name associated with each number.

Below is the code for the map I have created using the tmap package. The shapefile of the neighborhoods is Neighborhood_MN and the column with the name of the neighborhood is 'ntaname'.

neighborhood_colors <- c("#8dd3c7", "#ffffb3", "#bebada", "#fb8072", "#80b1d3", "#fdb462" ,"#b3de69", "#fccde5", "#d9d9d9", "#bc80bd", "#ccebc5" ,"#ffed6f")

tm_shape(Neighborhood_MN) +
  tm_polygons(col = "ntaname", title = "Neighborhoods", palette = neighborhood_colors , alpha = 1, scale = 1, size = 100)+
  tm_legend(show = TRUE) +
  tm_layout("Manhattan Neighborhoods",
            legend.title.size = 1,
            legend.text.size = 0.6,
            legend.position = c("left","top"),
            legend.bg.color = "white",
            legend.bg.alpha = 1)

How can I associate a number to each neighborhood name that would display on the map?

Karen
  • 1
  • 2
  • 1
    [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. We don't have your data, and we can't see any of your output – camille Aug 18 '21 at 19:27
  • You may use `match(neighborhood_colors, unique(neighborhood_colors))` or with `as.integer(factor(neighborhood_colors))` – akrun Aug 18 '21 at 19:30

0 Answers0