Skip to content

Warning from guide_axis() with 3.5.0 rc #5684

Closed as not planned
Closed as not planned
@gavinsimpson

Description

@gavinsimpson

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.

library("mgcv")
#> Loading required package: nlme
#> This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
library("ggplot2")
`sim_sos_eg_data` <- function(n = 400, seed = NULL) {
  if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE)) {
    runif(1)
  }
  if (is.null(seed)) {
    RNGstate <- get(".Random.seed", envir = .GlobalEnv)
  } else {
    R.seed <- get(".Random.seed", envir = .GlobalEnv)
    set.seed(seed)
    RNGstate <- structure(seed, kind = as.list(RNGkind()))
    on.exit(assign(".Random.seed", R.seed, envir = .GlobalEnv))
  }
  f <- function(la, lo) { ## a test function...
    sin(lo) * cos(la - 0.3)
  }
  ## generate with uniform density on sphere...
  lo <- runif(n) * 2 * pi - pi ## longitude
  la <- runif(3 * n) * pi - pi / 2
  ind <- runif(3 * n) <= cos(la)
  la <- la[ind]
  la <- la[seq_len(n)]
  ff <- f(la, lo)
  y <- ff + rnorm(n) * 0.2 ## test data
  out <-data.frame(latitude = la * 180 / pi,
    longitude = lo * 180 / pi, y = y)
  out
}
sos_df <- sim_sos_eg_data(n = 400, seed = 0)
m_sos <- gam(y ~ s(latitude, longitude, bs = "sos", k = 60), data = sos_df)
new_df <- with(sos_df,
  expand.grid(longitude = seq(min(longitude), max(longitude), length = 15),
    latitude = seq(min(latitude), max(latitude), length = 15)))
# sm <- smooth_estimates(m_sos, n = 25)
p <- predict(m_sos, newdata = new_df)
new_df$.fitted <- p

new_df |>
    ggplot(aes(x = longitude, y = latitude)) +
    geom_tile(aes(fill = .fitted)) +
    coord_map(projection = "orthographic",
        orientation = c(20, 0, 0)) +
    guides(fill = guide_colourbar(title = "Partial effect",
            direction = "vertical",
            barheight = grid::unit(0.25, "npc")),
        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

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:

library("ggplot2")
library("gamair")
library("mgcv")
#> Loading required package: nlme
#> This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
data(chl, package = "gamair") 
m <- gam(chl ~ s(lat, lon, bs = "sos"), data = chl, method = "REML") 
new_chl <- with(chl, expand.grid(lon = seq(min(lon), max(lon), length = 15),
    lat = seq(min(lat), max(lat), length = 15)))
     
pdat <- predict(m, newdata = new_chl)
new_chl$.fitted <- pdat
ggplot(chl, aes(x = lon, y = lat)) +
    geom_tile(data = new_chl, aes(x = lon, y = lat, fill = .fitted)) +
    #geom_point() +
    coord_map("orthographic", orientation = c(20, 0, 0)) +
    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

This version illustrates that the guides_axis() doesn't change the angle of the tick labels

I 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()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions