2

I have downloaded maps from a database that I want to plot in ggplot. The maps are all SpatialPolygonDataframes in class. My code produced rugged edges, so I tried to use a ksmooth function to the object. That helped a bit, but I still get some weird edges for some borders.

My code goes something like this

norway2 <- readOGR(dsn="path", use_iconv = TRUE, encoding = "UTF-8")
akershus <- #"Taking out" one county
q <- ggplot(data = merged, aes(x = long, y = lat, group = group))
q <- q + geom_polygon(color = "white", aes(fill = Ex),size = 0.05)
q <- q + scale_fill_gradient2(trans = "log", low = "white", high = "darkblue", guide = FALSE)
q <- q + theme(panel.background = element_rect(fill = "white", colour = "grey"),
             panel.grid.major = element_line(colour = "white"))
q

This plot gives me something like

Plot 1

I have understood that I can smooth the object a little bit using something like

norway3_smooth <-smooth(norway3, method = "ksmooth", smoothness = 2.8) 

This however is not really satisfactory. I get a plot like this, with some of the edges smoothed and others not.

enter image description here

Does anyone know of a way to smooth all the lines in a similar manner. Potentially using ggplot itself?

pApaAPPApapapa
  • 385
  • 2
  • 4
  • 12
  • 2
    How about https://cran.r-project.org/web/packages/rmapshaper/vignettes/rmapshaper.html or https://gis.stackexchange.com/questions/243569/simplify-polygons-of-sf-object ? They keywords to look for are "border simplify r". – Roman Luštrik Nov 29 '18 at 08:49
  • @RomanLuštrik, This was exactly what I was looking for. I searched a lot for it, but probably used the wrong keywords. Appreciate it! – pApaAPPApapapa Nov 29 '18 at 09:36

0 Answers0