bhaskarvk / tilegramsR

R wrapper for Tilegrams
https://bhaskarvk.github.io/tilegramsR/
Other
52 stars 2 forks source link

Plotting sf objects in ggplot2 #5

Open thomasjwood opened 7 years ago

thomasjwood commented 7 years ago

wonderful package, hope you could figure out a problem I'm having fortifying your sf objects for plotting in ggplot2.

library(tilegramsR)
library(ggplot2)
data(sf_DKOS_CD_Hexmap_v1.1)
d2 <-  fortify(as(sf_DKOS_CD_Hexmap_v1.1, "Spatial"),
               region = "STATENAME")

ggplot() + 
  geom_polygon(aes(x = long, y = lat, group = group, fill = id),
               data = d2,
               color = "black") + 
  guides(fill = FALSE) 

which returns

image

i wonder--why are there those superfluous interior borders in CA, TX, WI, etc?

bhaskarvk commented 7 years ago

Looks like https://github.com/edzer/sfr/issues/275. For now , call the precision method before converting it into spatial. On a sidenote if you build 'ggplot2' from GH repo (sf branch) devtools::install_github('tidyverse/ggplot2', ref='sf'), you will be able to use sf object as is, w/o needing to cast them to sp objects.

I'll keep this defect open for tracking purposes.