Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortify is not working anymore when parameter 'region' is specified #1447

Closed
matteodefelice opened this issue Dec 23, 2015 · 6 comments
Closed

Fortify is not working anymore when parameter 'region' is specified #1447

matteodefelice opened this issue Dec 23, 2015 · 6 comments

Comments

@matteodefelice
Copy link

@matteodefelice matteodefelice commented Dec 23, 2015

I load a shapefile:

test = readOGR('.', 'countries_EU')
head(test)
CNTR_ID SHAPE_AREA SHAPE_LEN
0 AD 0.05113435 1.04459
1 AE 6.32022050 23.10413
2 AL 3.05409305 10.99885
3 AM 3.14251031 13.45487
4 AT 10.02825446 24.85974
5 AZ 9.18575578 28.15200
test_f = fortify(test)
Regions defined for each Polygons

Instead:

test_f = fortify(test, region = 'CNTR_ID')
Error in get("rgeos", envir = .MAPTOOLS_CACHE) : object 'rgeos' not found

The same code has been working for weeks with the previous version of ggplot2.

@matteodefelice

This comment has been minimized.

Copy link
Author

@matteodefelice matteodefelice commented Dec 23, 2015

I was wrong, it's not about ggplot2. I close this issue.

@davben

This comment has been minimized.

Copy link

@davben davben commented Dec 29, 2015

I've run into the same error message and had to resort to using an older version of ggplot2. I'd greatly appreciate it, if you could you explain what caused the issue and how you've solved it.

@matteodefelice

This comment has been minimized.

Copy link
Author

@matteodefelice matteodefelice commented Dec 29, 2015

Unfortunately I don't remember what I did but I remember for sure that it wasn't due to ggplot2.

@hrbrmstr

This comment has been minimized.

Copy link
Contributor

@hrbrmstr hrbrmstr commented Dec 31, 2015

It's also broken in broom::tidy (which copied the fortify code for spatial objects) as well. I'll see if I can poke at it.

@hrbrmstr

This comment has been minimized.

Copy link
Contributor

@hrbrmstr hrbrmstr commented Dec 31, 2015

OK, all you have to do is library(maptools). It probably has something to do with the new base map packages.

library(dplyr)
library(broom)
library(rgeos)
library(rgdal)
library(maptools)
library(ggplot2)
library(ggalt) # devtools::install_github("hrbrmstr/ggalt")
library(ggthemes)
library(viridis)

URL <- "https://www.wordspeak.org/d3-projects/data/au-states.geojson"
fil <- basename(URL)
if (!file.exists(fil)) download.file(URL, fil)

aus <- readOGR(fil, "OGRGeoJSON")

#' new way to 'fortify' with broom
aus_tidy <- tidy(aus, region="STATE_NAME")

#' Lambert Conformal Conic
lcc_proj <- "+proj=lcc +lat_1=-18 +lat_2=-36 +lat_0=-25 +lon_0=135 +ellps=aust_SA  +units=m +no_defs"

gg <- ggplot()
gg <- gg + geom_map(data=aus_tidy, map=aus_tidy,
                    aes(x=long, y=lat, map_id=id, fill=id),
                    color="#7f7f7f", size=0.15)
gg <- gg + scale_fill_viridis(name="", discrete=TRUE)
gg <- gg + coord_proj(lcc_proj)
gg <- gg + theme_map()
gg <- gg + theme(legend.position="right")
gg
pattyf added a commit to dlab-geo/rCensusACS that referenced this issue Jan 14, 2016
Per jacobo email *thanks*, added maptools library (see  tidyverse/ggplot2#1447, comment #6.)
d-qn added a commit to d-qn/swiMap that referenced this issue Jun 8, 2016
@robcrystalornelas

This comment has been minimized.

Copy link

@robcrystalornelas robcrystalornelas commented Jun 14, 2016

Thanks for this solution! @hrbrmstr

area-man added a commit to area-man/R-space that referenced this issue Nov 1, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.