Skip to content

Updates CoordProj to new API#69

Open
eliocamp wants to merge 3 commits intohrbrmstr:masterfrom
eliocamp:new-coord-proj
Open

Updates CoordProj to new API#69
eliocamp wants to merge 3 commits intohrbrmstr:masterfrom
eliocamp:new-coord-proj

Conversation

@eliocamp
Copy link
Copy Markdown

@eliocamp eliocamp commented Apr 17, 2020

This is an attempt to update CoordProj to the current ggplot2 Coord extension API (#62 ). I don't know if it's correct, but at least the examples do run.

library(ggplot2)
library(ggalt)
#> Registered S3 methods overwritten by 'ggalt':
#>   method                  from   
#>   grid.draw.absoluteGrob  ggplot2
#>   grobHeight.absoluteGrob ggplot2
#>   grobWidth.absoluteGrob  ggplot2
#>   grobX.absoluteGrob      ggplot2
#>   grobY.absoluteGrob      ggplot2

world <- map_data("world")
world <- world[world$region != "Antarctica",]

gg <- ggplot()
gg <- gg + geom_cartogram(data=world, map=world,
                    aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj("+proj=wintri")
gg

# U.S.A. Albers-style
usa <- world[world$region == "USA",]
usa <- usa[!(usa$subregion %in% c("Alaska", "Hawaii")),]

gg <- ggplot()
gg <- gg + geom_cartogram(data=usa, map=usa,
                    aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj(
             paste0("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96",
                    " +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"))
gg

# Showcase Greenland (properly)
greenland <- world[world$region == "Greenland",]

gg <- ggplot()
gg <- gg + geom_cartogram(data=greenland, map=greenland,
                    aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj(
             paste0("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0",
                    " +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
gg

Created on 2020-04-17 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                         
#>  version  R version 3.6.3 (2020-02-29)  
#>  os       elementary OS 5.1.3 Hera      
#>  system   x86_64, linux-gnu             
#>  ui       X11                           
#>  language en_US                         
#>  collate  en_US.UTF-8                   
#>  ctype    en_US.UTF-8                   
#>  tz       America/Argentina/Buenos_Aires
#>  date     2020-04-17                    
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date       lib source                   
#>  ash            1.0-15     2015-09-01 [1] CRAN (R 3.6.0)           
#>  assertthat     0.2.1      2019-03-21 [1] CRAN (R 3.6.0)           
#>  backports      1.1.5      2019-10-02 [1] CRAN (R 3.6.1)           
#>  callr          3.4.2      2020-02-12 [1] CRAN (R 3.6.2)           
#>  cli            2.0.2      2020-02-28 [1] CRAN (R 3.6.3)           
#>  colorspace     1.4-1      2019-03-18 [1] CRAN (R 3.6.0)           
#>  crayon         1.3.4      2017-09-16 [1] CRAN (R 3.6.2)           
#>  curl           4.3        2019-12-02 [1] CRAN (R 3.6.2)           
#>  desc           1.2.0      2018-05-01 [1] CRAN (R 3.6.0)           
#>  devtools       2.2.2      2020-02-17 [1] CRAN (R 3.6.3)           
#>  digest         0.6.25     2020-02-23 [1] CRAN (R 3.6.3)           
#>  dplyr          0.8.5      2020-03-07 [1] CRAN (R 3.6.3)           
#>  ellipsis       0.3.0      2019-09-20 [1] CRAN (R 3.6.1)           
#>  evaluate       0.14       2019-05-28 [1] CRAN (R 3.6.0)           
#>  extrafont      0.17       2014-12-08 [1] CRAN (R 3.6.0)           
#>  extrafontdb    1.0        2012-06-11 [1] CRAN (R 3.6.0)           
#>  fansi          0.4.1      2020-01-08 [1] CRAN (R 3.6.2)           
#>  farver         2.0.3      2020-01-16 [1] CRAN (R 3.6.2)           
#>  fs             1.3.2      2020-03-05 [1] CRAN (R 3.6.3)           
#>  ggalt        * 0.6.2      2020-04-17 [1] local                    
#>  ggplot2      * 3.3.0      2020-03-05 [1] CRAN (R 3.6.3)           
#>  glue           1.3.2      2020-03-12 [1] CRAN (R 3.6.3)           
#>  gtable         0.3.0      2019-03-25 [1] CRAN (R 3.6.0)           
#>  highr          0.8        2019-03-20 [1] CRAN (R 3.6.0)           
#>  htmltools      0.4.0      2019-10-04 [1] CRAN (R 3.6.1)           
#>  httr           1.4.1      2019-08-05 [1] CRAN (R 3.6.1)           
#>  KernSmooth     2.23-16    2019-10-15 [4] CRAN (R 3.6.1)           
#>  knitr          1.28       2020-02-06 [1] CRAN (R 3.6.2)           
#>  labeling       0.3        2014-08-23 [1] CRAN (R 3.6.0)           
#>  lifecycle      0.2.0      2020-03-06 [1] CRAN (R 3.6.3)           
#>  magrittr       1.5        2014-11-22 [1] CRAN (R 3.6.0)           
#>  maps           3.3.0      2018-04-03 [1] CRAN (R 3.6.3)           
#>  MASS           7.3-51.5   2019-12-20 [4] CRAN (R 3.6.2)           
#>  memoise        1.1.0      2017-04-21 [1] CRAN (R 3.6.0)           
#>  mime           0.9        2020-02-04 [1] CRAN (R 3.6.2)           
#>  munsell        0.5.0      2018-06-12 [1] CRAN (R 3.6.0)           
#>  pillar         1.4.3      2019-12-20 [1] CRAN (R 3.6.2)           
#>  pkgbuild       1.0.6      2019-10-09 [1] CRAN (R 3.6.2)           
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 3.6.1)           
#>  pkgload        1.0.2      2018-10-29 [1] CRAN (R 3.6.0)           
#>  prettyunits    1.1.1      2020-01-24 [1] CRAN (R 3.6.2)           
#>  processx       3.4.2      2020-02-09 [1] CRAN (R 3.6.2)           
#>  proj4          1.0-10     2020-03-02 [1] CRAN (R 3.6.3)           
#>  ps             1.3.2      2020-02-13 [1] CRAN (R 3.6.2)           
#>  purrr          0.3.3      2019-10-18 [1] CRAN (R 3.6.2)           
#>  R6             2.4.1.9000 2020-01-21 [1] Github (r-lib/R6@8e0b318)
#>  RColorBrewer   1.1-2      2014-12-07 [1] CRAN (R 3.6.0)           
#>  Rcpp           1.0.4      2020-03-17 [1] CRAN (R 3.6.3)           
#>  remotes        2.1.1      2020-02-15 [1] CRAN (R 3.6.3)           
#>  rlang          0.4.5      2020-03-01 [1] CRAN (R 3.6.3)           
#>  rmarkdown      2.1        2020-01-20 [1] CRAN (R 3.6.2)           
#>  rprojroot      1.3-2      2018-01-03 [1] CRAN (R 3.6.0)           
#>  Rttf2pt1       1.3.8      2020-01-10 [1] CRAN (R 3.6.2)           
#>  scales         1.1.0      2019-11-18 [1] CRAN (R 3.6.2)           
#>  sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 3.6.0)           
#>  stringi        1.4.6      2020-02-17 [1] CRAN (R 3.6.3)           
#>  stringr        1.4.0      2019-02-10 [1] CRAN (R 3.6.0)           
#>  testthat       2.3.2      2020-03-02 [1] CRAN (R 3.6.3)           
#>  tibble         2.1.3      2019-06-06 [1] CRAN (R 3.6.0)           
#>  tidyselect     1.0.0      2020-01-27 [1] CRAN (R 3.6.2)           
#>  usethis        1.5.1      2019-07-04 [1] CRAN (R 3.6.1)           
#>  withr          2.1.2      2018-03-15 [1] CRAN (R 3.6.0)           
#>  xfun           0.12       2020-01-13 [1] CRAN (R 3.6.2)           
#>  xml2           1.2.5      2020-03-11 [1] CRAN (R 3.6.3)           
#>  yaml           2.2.1      2020-02-01 [1] CRAN (R 3.6.2)           
#> 
#> [1] /home/elio/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

@CrHvG
Copy link
Copy Markdown

CrHvG commented Apr 17, 2020

Thanks all for working on this. It fixed the old error, but I still can't run the example, as its throwing a new one :

Error in expand_default(scale) : could not find function "expand_default"

ggtern is loaded

@eliocamp
Copy link
Copy Markdown
Author

That's a strange error. expand_default is an internal function in ggalt so it should be there. Are you installing this PR (devtools::install_github("eliocamp/ggalt@new-coord-proj"))? Can you post a reproducible example?

@CrHvG
Copy link
Copy Markdown

CrHvG commented Apr 17, 2020

That seemed to do it. Sorry for the confusion. Beers on me!

@ChrisFishCahill
Copy link
Copy Markdown

Seems to be working for me, too. My projections (not just the examples) are behaving again. Nice fix @eliocamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants