I am wondering how to create minimal example shapefile of certain countries such as US, Germany, or Brazil with fake data. I am new with geospatial data and it is nice to know how to create minimal geospatial data in R. I need reproducible shapefile because I want to create my minimal solution on it and test my approach.

How can I make this happen minimal shapefile of certain countries with fake data in R? Any quick approach to do it? Any idea?


I am going to create shapefile of certain countries such as US, Germany or vice-versa by state or county level but fill it with fake random data for reproducible use. Any better idea?

closed as unclear what you're asking by Vince, Spacedman, Evil Genius, xunilk, BERA Jun 23 '18 at 10:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • A minimal example of what? What kind of data? Please Edit the question. – Vince Jun 22 '18 at 16:55
  • Perhaps easier to use one of the built-in data sets from one of the R packages and modify some attributes? You might need to be a bit more specific. – Spacedman Jun 22 '18 at 17:12
  • @Vince Sorry if my question is not crystal-clear to you. I want to create shapefile of certain countries (US,Brazil, or Germany) with certain administrative level (state or county or other types of administrative level). Any smart move? – Jerry Jun 23 '18 at 9:20
  • @Spacedman sorry for my late reply, I just updated my post with few line more specification. Any better idea? – Jerry Jun 23 '18 at 9:21

I am going to assume that you want polygon outlines of those countries. I will leave it up to you make fake data. I am also going to assume that you in fact want on-disk shapefiles and are not using the term as shorthand for spatial data.


us      <- st_as_sf(map("state", plot = FALSE, fill = TRUE))
germany <- st_as_sf(map("worldHires", "Germany", plot = FALSE, fill = TRUE))
brazil  <- st_as_sf(map("worldHires", "Brazil", plot = FALSE, fill = TRUE))

par(mfrow = c(1, 3), mar = c(0,0,0,0))

write_sf(us, "us.shp")
write_sf(germany, "germany.shp")
write_sf(brazil, "brazil.shp")

enter image description here

  • Thanks for your help. Is that possible to produce shapefile for Germany with respective administrative level (state, province, county and so on, just like Eurostat shapefile). Any better idea? – Jerry Jun 23 '18 at 9:53
  • I doubt there are existing built in polygons with this detail. You probably need to download them separately apart from R. – jsta Aug 8 '18 at 16:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.