How to solve problem with reading a shapefile in R

How do I show a map that is in shapefile format that is in a zip file. The file is this:

I tried to do the following:


temp <- tempfile()
data <- readOGR(unz(temp, "41MUE250GC_SIR.shp"))

But it did not work.

The map will look like the one below:

enter image description here

Probably better to use sf than rgdal it is just a better package for working with spatial data.

You could do this:


temp <- tempfile()
data <- st_read(unz(temp, "41MUE250GC_SIR.shp"))

# Unzip the contents of the temp and save in temp2
temp2 <- tempfile()
unzip(zipfile = temp, exdir = temp2)

# Read using sf
municipios <- st_read(temp2)

Thanks for answering @williaml ! And to plot a graph similar to the one in the question, how do I do it? I made plot(municipios), but it shows two maps.


Use the $ for a particular column e.g. plot(municipios$your_column).

More info: 5. Plotting Simple Features • sf

Otherwise, you can use ggplot2, or other packages including leaflet, tmap, mapsf.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.