Closed gavinsimpson closed 8 months ago
A simpler reprex:
library(maps)
library(ggplot2)
nz <- map_data("nz")
ggplot(nz, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black") +
coord_map() +
guides(x = guide_axis(angle = 45))
#> Warning: `guide_axis()` cannot be used for .
#> ℹ Use one of x, y, or r instead.
Created on 2024-02-07 with reprex v2.1.0
The underlying issue is that coord_map()
is superseded by coord_sf()
and didn't recieve any guide updates. coord_sf()
did get the update, and the axis text angle works:
library(maps)
library(ggplot2)
nz <- map_data("nz")
ggplot(nz, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black") +
coord_sf(crs = 4326) +
guides(x = guide_axis(angle = 45))
Created on 2024-02-07 with reprex v2.1.0
I'm going to close this, as we're unlikely to update coord_map()
due to its superseded status.
We can re-open this issue if a similar problem emerges with coord_sf()
.
While I do understand your reasoning here, I think calling coord_map()
superseded is no longer appropriate if you are going to break perfectly fine code in later updates that you don't plan to include coord_map()
in.
In some ways a superseded function is actually safer than a stable function because it’s guaranteed never to change (for better or for worse).
is in the definition of superseded and while you haven't changed coord_map()
you have changed how it works. Where you have such highly-integrated functionality as you have in ggplot2 with all the different systems coming together, I don't know how you can hope to maintain something like coord_map()
if you don't plan to accommodate it into changes that happen in separate but related sub-systems of ggplot. I'd expect a stronger indication not to use this function.
Guess I need to figure out the correct incantation for coord_sf()
to get it to produce an orthographic projection...
A couple of points:
library(maps)
library(ggplot2)
packageVersion("ggplot2")
#> [1] '3.4.2'
nz <- map_data("nz")
ggplot(nz, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black") +
coord_map() +
guides(x = guide_axis(angle = 45))
Created on 2024-02-23 with reprex v2.1.0
theme()
incantations for rotated axis labels still work perfectly fine, so you have a viable alternative if you must use rotated axis labels with coord_map()
.library(maps)
library(ggplot2)
packageVersion("ggplot2")
#> [1] '3.5.0.9000'
nz <- map_data("nz")
ggplot(nz, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", colour = "black") +
coord_map() +
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1, vjust = 1))
Created on 2024-02-23 with reprex v2.1.0
The axis angle also wasn't applied in previous versions, see example below.
Sorry, I should have been clearer; I shouldn't have implied the code "worked" in the sense that the tick labels were rotated. I meant from the point of view of running without warning. That the guides thing doesn't work in earlier versions of ggplot is not a gratia problem but a ggplot2 problem (that I admittedly didn't catch at the time all this got written) - I was trying to have a consistent way of changing the angle of axis labels across multiple different types on plot in the package and was using guides()
to do that,
It is a warning not an error, so 'break perfectly fine code' is a bit of a stretch here.
That's semantics when you are talking about using ggplot in a package that is on CRAN. If you pushed this rc to CRAN today, my package would be broken as far as CRAN is concerned because it now emits a warning. While I appreciate there is an easy fix for the average user (just ignore the warning or use theme()
to modify the angle), I can't do that as a package developer, and simply moving to coord_sf()
(with the correct CRS) isn't working (as implied on the coord_map()
page) for this example.
I concede that the meaning of "superseded" is somewhat ambiguous when it comes to modular APIs like ggplot2, but I don't think we are interpreting it wrong (but clearly different than you). If a function is superseded the promise is that code that worked prior to the superseding will continue to work. That promise is uphold here. We do not want to mark the function as deprecated as a few still find it valuable, but it is vestigal and users cannot expect new functionality (which the new guide system is) to work with it
@thomasp85 I guess this is a clash between the "User" use-case and the "Developer" use-case, which lifecycle doesn't seem to address, but, from the lifecycle descriptions of the statuses
A superseded function will not emit a warning...
is ambiguous as I guess the warning that I report here is not a) from lifecycle, nor b) from coord_map()
. So by the letter of the law, your and @teunbrand's interpretation meets the stated contracted, but from where I'm sitting as the developer needing to fix code, these changes break the spirit of the law.
I's almost as though lifecycle needs a deprecated-for-developers status, but that's not something for discussion here.
Thanks both!
I emphasise with that viewpoint. However, I would actually argue that your old code using coord_map()
was fixed in this release since the fact that no warning was emitted was clearly a bug (which led you to believe that your code was working correctly).
I don't think your reading of "A superseded function will not emit a warning..." is correct. In my head it references the warnings from lifecycle as it talks about the differences to a deprecated function. The alternative would be quite crazy, i.e. a superseded function will never emit a warning no matter whether you use it correctly
If we're not talking about a highly modular system like ggplot2, then I would expect coord_map()
to continue to work without warnings regardless of what other changes are made in the package or in R while in superseded state. For example, something like gather()
vs pivot_longer()
; I would expect the former to continue to work without any warnings as long as it was being invoked correctly. I.e. fixing issues elsewhere shouldn't "break" gather()
, in the sense that I can no longer use gather()
in my package because perfectly correct code now results in a warning. If gather()
started working like coord_map()
is now in the rc, I'd expect it to either be deprecated — the package has eventually moved on and it is no longer possible to maintain it as a working function — or for it to be fixed-up to avoid the warning.
That's my view from the developer perspective. I appreciate that from the user-perspective, deprecating coord_map()
when they could avoid using the new guides()
would be overkill.
When it comes to highly modular packages, I would view it as still a whole that should work together. Once things stop working together, frustrations will kick in when users try to do something perfectly valid with one module of ggplot that no-longer works with the other module. In that case I would just bite the bullet and deprecate the thing that no-longer works with the new and improved module.
(The above is ignoring the issue that guides()
actually had bugs in it when used with coord_map()
- that adds a complication to the discussion, I agree)
Where would you draw the line? Where would you deprecate coord_map()
? How much of the other ggplot functionality needs to not work with coord_map()
before you deprecated it? For me that would be now, speaking as a developer user of ggplot. I appreciate you need to cater for user users too.
In this instance, moving to use the suggested function that has superseded coord_map()
isn't trivial; I am currently unable to find an invocation of coord_sf()
to gets me an orthographic projection and what's stated in coord_map()
as to what needs to be done to a ggplot call to migrate to coord_sf()
is either incorrect or insufficient to replicate behaviour of coord_map()
. But, that's outwith the discussion here.
My point above was that your code was not perfectly correct, even in the old version. It was a bug that it did not throw a warning. This bug has been fixed now and would have been irrespective of the state of the function
My point above was that your code was not perfectly correct
But coord_map()
did the right thing, right? It was the guides()
call that wasn't? Perhaps this is what I'm struggling with; where was the bug? The other example I showed at least did draw axes and ticks even if the labels weren't rotated. I'd be happy if you'd maintained the old behaviour with new guides()
code — on my own time line I could migrate to coord_sf()
.
But the change to guides()
has changed the behaviour of coord_map() + guides(x = guide_axis())
and it hasn't fixed anything. At this point I consider coord_map()
more than just superseded.
coord_map() + guides(x = guide_axis())
was the bug. It never worked in any way and ggplot2 should always have emitted a warning to let the user know this. It didn't before, now it does so the bug is fixed
@gavinsimpson Out of curiousity, did you ever get the email from CRAN about this?
In the end, no; I think you'd fixed some things that were causing errors and warnings that I got a bug report over and to keep testing time down this particular functionality was being skipped on CRAN. I've since swapped out the coord_map()
for something that is not 100% right but is working with coord_sf()
(your mentioning that I need default_crs
and crs
) and I'm planning on implementing Edzer's more correct solution from the sf issue I raised soon.
While checking out the changes to the guides in the 3.5.0 release candidate I found an issue with
guide_axis()
that represents a difference over 3.4.0 behaviour.I've tried to make this as minimal as I can without my actually doing a lot of work with maps/projections. From my limited testing, I needed something this complicated as simple usage of
guide_axis()
worked as expected.The regexp below simulates data on a sphere, fits a GAM to those data using mgcv and a spline on the sphere basis, and then plots the estimated spline using
coord_map()
to produce an orthographic projection.Created on 2024-02-07 with reprex v2.1.0
I expected no warning as all I'm trying to do is change the angle of the tick labels on the x axis.
I'll also note that this plot doesn't actually have an ticks on either the x or y axis; which I assume is expected given the plot is of the whole globe?
Note that a more elaborate version of this code is used in an R package where this kind of plot could be used to plot any area of the globe.
Here's another example of the same behaviour but which illustrates that
guide_axis()
doesn't change the angle of the tick labels, but which requires installation of the {gamair} package:Created on 2024-02-07 with reprex v2.1.0
This version illustrates that the
guides_axis()
doesn't change the angle of the tick labelsI expected that there would be no warning, and the tick labels on the x axis would be drawn at 45 degrees to the axis.
session info
Output from `sessioninfo::session_info()` ```r ─ Session info ────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.3.2 (2023-10-31) os Ubuntu 20.04.6 LTS system x86_64, linux-gnu ui X11 language en_GB:en collate en_GB.UTF-8 ctype en_GB.UTF-8 tz Europe/Copenhagen date 2024-02-07 pandoc 2.5 @ /usr/bin/ (via rmarkdown) ─ Packages ────────────────────────────────────────────────────────────────────────────────────────── ! package * version date (UTC) lib source abind 1.4-5 2016-07-21 [1] RSPM (R 4.3.0) ADGofTest 0.3 2011-12-28 [1] RSPM (R 4.3.0) boot 1.3-28.1 2022-11-22 [1] RSPM (R 4.3.0) brio 1.1.4 2023-12-10 [1] RSPM (R 4.3.2) bslib 0.6.1 2023-11-28 [1] RSPM (R 4.3.2) cachem 1.0.8 2023-05-01 [1] RSPM (R 4.3.0) callr 3.7.3 2022-11-02 [1] RSPM (R 4.3.0) class 7.3-22 2023-05-03 [1] RSPM (R 4.3.0) classInt 0.4-10 2023-09-05 [1] RSPM (R 4.3.1) cli 3.6.2 2023-12-11 [1] RSPM (R 4.3.2) clipr 0.8.0 2022-02-22 [1] RSPM (R 4.3.0) colorspace 2.1-0 2023-01-23 [1] RSPM (R 4.3.0) copula 1.1-3 2023-12-07 [1] RSPM (R 4.3.2) crayon 1.5.2 2022-09-29 [1] RSPM (R 4.3.0) curl 5.2.0 2023-12-08 [1] RSPM (R 4.3.2) DBI 1.2.1 2024-01-12 [1] RSPM (R 4.3.2) desc 1.4.3 2023-12-10 [1] RSPM (R 4.3.2) devtools * 2.4.5 2022-10-11 [1] RSPM (R 4.3.1) diffviewer 0.1.1 2021-09-30 [1] RSPM (R 4.3.0) digest 0.6.34 2024-01-11 [1] RSPM (R 4.3.2) dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.3.2) e1071 1.7-14 2023-12-06 [1] RSPM (R 4.3.2) ellipsis 0.3.2 2021-04-29 [1] RSPM (R 4.3.0) evaluate 0.23 2023-11-01 [1] RSPM (R 4.3.2) evd 2.3-6.1 2022-07-04 [1] RSPM (R 4.3.0) fansi 1.0.6 2023-12-08 [1] RSPM (R 4.3.2) farver 2.1.1 2022-07-06 [1] RSPM (R 4.3.0) fastmap 1.1.1 2023-02-24 [1] RSPM (R 4.3.0) forcats 1.0.0 2023-01-29 [1] RSPM (R 4.3.0) fs 1.6.3 2023-07-20 [1] RSPM (R 4.3.1) gamlss.dist 6.1-1 2023-08-23 [1] RSPM (R 4.3.1) gamm4 * 0.2-6 2020-04-03 [1] RSPM (R 4.3.0) generics 0.1.3 2022-07-05 [1] RSPM (R 4.3.0) ggokabeito 0.1.0 2021-10-18 [1] RSPM (R 4.3.0) ggplot2 * 3.5.0 2024-02-07 [1] Github (tidyverse/ggplot2@fa6d68d) GJRM * 0.2-6.5 2024-01-25 [1] RSPM (R 4.3.2) glue 1.7.0 2024-01-09 [1] RSPM (R 4.3.2) gmp 0.7-4 2024-01-15 [1] RSPM (R 4.3.2) VP gratia * 0.8.9.4 2024-02-03 [?] load_all() (on disk 0.8.9.3) gsl 2.1-8 2023-01-24 [1] RSPM (R 4.3.0) gtable 0.3.4 2023-08-21 [1] RSPM (R 4.3.1) hms 1.1.3 2023-03-21 [1] RSPM (R 4.3.0) htmltools 0.5.7 2023-11-03 [1] RSPM (R 4.3.2) htmlwidgets 1.6.4 2023-12-06 [1] RSPM (R 4.3.2) httpgd 1.3.1 2023-01-30 [1] RSPM (R 4.3.0) httpuv 1.6.14 2024-01-26 [1] RSPM (R 4.3.2) ismev 1.42 2018-05-10 [1] RSPM (R 4.3.0) isoband 0.2.7 2022-12-20 [1] RSPM (R 4.3.0) jquerylib 0.1.4 2021-04-26 [1] RSPM (R 4.3.0) jsonlite 1.8.8 2023-12-04 [1] RSPM (R 4.3.2) KernSmooth 2.23-22 2023-07-10 [1] RSPM (R 4.3.1) knitr 1.45 2023-10-30 [1] RSPM (R 4.3.2) labeling 0.4.3 2023-08-29 [1] RSPM (R 4.3.1) later 1.3.2 2023-12-06 [1] RSPM (R 4.3.2) lattice 0.22-5 2023-10-24 [1] RSPM (R 4.3.2) lifecycle 1.0.4 2023-11-07 [1] RSPM (R 4.3.2) lme4 * 1.1-35.1 2023-11-05 [1] RSPM (R 4.3.2) magic 1.6-1 2022-11-16 [1] RSPM (R 4.3.0) magrittr 2.0.3 2022-03-30 [1] RSPM (R 4.3.0) mapproj 1.2.11 2023-01-12 [1] RSPM (R 4.3.0) maps 3.4.2 2023-12-15 [1] RSPM (R 4.3.2) MASS 7.3-60.0.1 2024-01-13 [1] RSPM (R 4.3.2) Matrix * 1.6-5 2024-01-11 [1] RSPM (R 4.3.2) matrixStats 1.2.0 2023-12-11 [1] RSPM (R 4.3.2) memoise 2.0.1 2021-11-26 [1] RSPM (R 4.3.0) mgcv * 1.9-1 2023-12-21 [1] RSPM (R 4.3.2) mime 0.12 2021-09-28 [1] RSPM (R 4.3.0) miniUI 0.1.1.1 2018-05-18 [1] RSPM (R 4.3.0) minqa 1.2.6 2023-09-11 [1] RSPM (R 4.3.1) mitools 2.4 2019-04-26 [1] RSPM (R 4.3.0) mnormt 2.1.1 2022-09-26 [1] RSPM (R 4.3.0) munsell 0.5.0 2018-06-12 [1] RSPM (R 4.3.0) mvnfast 0.2.8 2023-02-23 [1] RSPM (R 4.3.0) mvtnorm 1.2-4 2023-11-27 [1] RSPM (R 4.3.2) nlme * 3.1-164 2023-11-27 [1] RSPM (R 4.3.2) nloptr 2.0.3 2022-05-26 [1] RSPM (R 4.3.0) numDeriv 2016.8-1.1 2019-06-06 [1] RSPM (R 4.3.0) patchwork 1.2.0 2024-01-08 [1] RSPM (R 4.3.2) pcaPP 2.0-4 2023-12-07 [1] RSPM (R 4.3.2) pillar 1.9.0 2023-03-22 [1] RSPM (R 4.3.0) pkgbuild 1.4.3 2023-12-10 [1] RSPM (R 4.3.2) pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.3.0) pkgload 1.3.4 2024-01-16 [1] RSPM (R 4.3.2) processx 3.8.3 2023-12-10 [1] RSPM (R 4.3.2) profvis 0.3.8 2023-05-02 [1] RSPM (R 4.3.0) promises 1.2.1 2023-08-10 [1] RSPM (R 4.3.1) proxy 0.4-27 2022-06-09 [1] RSPM (R 4.3.0) ps 1.7.6 2024-01-18 [1] RSPM (R 4.3.2) pspline 1.0-19 2022-02-20 [1] RSPM (R 4.3.0) psych 2.4.1 2024-01-18 [1] RSPM (R 4.3.2) purrr 1.0.2 2023-08-10 [1] RSPM (R 4.3.1) R.cache 0.16.0 2022-07-21 [1] RSPM (R 4.3.0) R.methodsS3 1.8.2 2022-06-13 [1] RSPM (R 4.3.0) R.oo 1.26.0 2024-01-24 [1] RSPM (R 4.3.2) R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.3.2) R6 2.5.1 2021-08-19 [1] RSPM (R 4.3.0) RColorBrewer 1.1-3 2022-04-03 [1] RSPM (R 4.3.0) Rcpp 1.0.12 2024-01-09 [1] RSPM (R 4.3.2) readr 2.1.5 2024-01-10 [1] RSPM (R 4.3.2) remotes 2.4.2.1 2023-07-18 [1] RSPM (R 4.3.1) reprex 2.1.0 2024-01-11 [1] RSPM (R 4.3.2) rlang 1.1.3 2024-01-10 [1] RSPM (R 4.3.2) rmarkdown 2.25 2023-09-18 [1] RSPM (R 4.3.1) Rmpfr 0.9-5 2024-01-21 [1] RSPM (R 4.3.2) rprojroot 2.0.4 2023-11-05 [1] RSPM (R 4.3.2) rstudioapi 0.15.0 2023-07-07 [1] RSPM (R 4.3.1) sass 0.4.8 2023-12-06 [1] RSPM (R 4.3.2) scales 1.3.0 2023-11-28 [1] RSPM (R 4.3.2) scam * 1.2-15 2024-01-25 [1] RSPM (R 4.3.2) sessioninfo 1.2.2 2021-12-06 [1] RSPM (R 4.3.0) sf 1.0-15 2023-12-18 [1] RSPM (R 4.3.2) shiny * 1.8.0 2023-11-17 [1] CRAN (R 4.3.2) stabledist 0.7-1 2016-09-12 [1] RSPM (R 4.3.0) stringi 1.8.3 2023-12-11 [1] RSPM (R 4.3.2) stringr 1.5.1 2023-11-14 [1] RSPM (R 4.3.2) styler 1.10.2.9000 2024-02-07 [1] Github (r-lib/styler@775c399) survey 4.2-1 2023-05-03 [1] RSPM (R 4.3.0) survival 3.5-7 2023-08-14 [1] RSPM (R 4.3.1) systemfonts 1.0.5 2023-10-09 [1] RSPM (R 4.3.2) testthat * 3.2.1 2023-12-02 [1] RSPM (R 4.3.2) tibble * 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) tidyr 1.3.1 2024-01-24 [1] RSPM (R 4.3.2) tidyselect 1.2.0 2022-10-10 [1] RSPM (R 4.3.0) trust 0.1-8 2020-01-10 [1] RSPM (R 4.3.0) tzdb 0.4.0 2023-05-12 [1] RSPM (R 4.3.0) units 0.8-5 2023-11-28 [1] RSPM (R 4.3.2) urlchecker 1.0.1 2021-11-30 [1] RSPM (R 4.3.0) usethis * 2.2.2 2023-07-06 [1] RSPM (R 4.3.1) utf8 1.2.4 2023-10-22 [1] RSPM (R 4.3.1) vctrs 0.6.5 2023-12-01 [1] RSPM (R 4.3.2) vdiffr 1.0.7 2023-09-22 [1] CRAN (R 4.3.1) VGAM 1.1-9 2023-09-19 [1] RSPM (R 4.3.1) VineCopula 2.5.0 2023-07-10 [1] RSPM (R 4.3.1) viridisLite 0.4.2 2023-05-02 [1] RSPM (R 4.3.0) waldo 0.5.2 2023-11-02 [1] RSPM (R 4.3.2) withr 3.0.0 2024-01-16 [1] RSPM (R 4.3.2) xfun 0.41 2023-11-01 [1] RSPM (R 4.3.2) xtable 1.8-4 2019-04-21 [1] RSPM (R 4.3.0) yaml 2.3.8 2023-12-11 [1] RSPM (R 4.3.2) [1] /home/user/R/x86_64-pc-linux-gnu-library/4.3 [2] /usr/local/lib/R/site-library [3] /usr/lib/R/site-library [4] /usr/lib/R/library V ── Loaded and on-disk version mismatch. P ── Loaded and on-disk path mismatch. ```