0

I have a point shapefile with cities (CitiesPoints), and a dataframe that assigns a number of libraries to some of those cities (df; the data is fictitious). I also have a polygon shapefile for the background.

I joined those files to create a map in which a point is generated for each city that has libraries, and the size of the point is determined by the number of libraries it has.

df$CityCode <- as.factor(df$CityCode)
Joint <- CitiesPoints %>% 
  left_join(df, by=c("link"="CityCode"))
tmap_mode("view")
tm_shape(Background) +
tm_borders() +
tm_shape(Joint) + tm_symbols(id = "localidad",
                              size = "BIBLIO",
                              col = "brown1")

However, when I hover over those points with the mouse, the city name shown is incorrect. Apparently, the top rows in the shape file (including those with no libraries, NA) are the ones being used to assign the labels.

Example

The correct label for this point should be “Rafaela”.

You can download the files I used here: Files

I would really appreciate the help!

Natalias
  • 179
  • 6

1 Answers1

0

I found a way to fix it. I created a new shapefile only containing the rows corresponding to the citys which have libraries.

Joint$BIBLIO[is.na(Joint$BIBLIO)] <- 0
JOINT2 = filter(Joint,BIBLIO>0)

Using this new shapefile, the automatic labels shown are now correct.

Natalias
  • 179
  • 6