-
Notifications
You must be signed in to change notification settings - Fork 96
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
st_contour causes "non-numeric argument" error. 'See Also' suggestion not supported. #465
Comments
|
Aaah, ok, thanks Edzer. I don't suppose there's any chance you could add your answer to the Thanks again. Finally getting into rasters and Edit: sorry to bother you again. Perhaps I've misunderstood something. If I pass to
Or via an intermediary
I get:
I was under the impression that this error shouldn't be seen when using
Looks 'normal' i.e. the same structure as a coastline
But it doesn't look like I can set one:
I would assume that NA values in the multipolygon geometries shouldn't cause the mapping error, they'd just not plot? Thanks again for your thoughts. |
The outputs of
The second option is less loss of information in my point of view. Here an example with your data: library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
#> Registered S3 methods overwritten by 'stars':
#> method from
#> st_bbox.SpatRaster sf
#> st_crs.SpatRaster sf
library(ggplot2)
f <- tempfile(fileext = ".asc")
curl::curl_download("https://raw.githubusercontent.com/SimonDedman/dBBMM_HomeRange/main/data/All_Rasters_Scaled.asc",
f)
lemons.ras <- read_stars(f) %>%
st_set_crs(2958)
stars:::is_curvilinear(lemons.ras)
#> [1] FALSE
# without transforming
ggplot() +
geom_stars(data = lemons.ras,
alpha = 0.5) +
geom_sf(data = st_contour(x = lemons.ras,
contour_lines = FALSE),
fill = NA, color = "orange") # Transforming
stars:::is_curvilinear(lemons.ras %>%
st_transform(4326))
#> [1] TRUE
# I will transform on the fly to manage the plotting with ggplot2. You can make permanent transforms.
ggplot() +
geom_stars(data = lemons.ras %>% st_transform(4326), # Raster layer transform
alpha = 0.5) +
geom_sf(data = st_contour(x = lemons.ras,
contour_lines = FALSE) %>%
st_transform(4326), # Vector transform after st_contour()
fill = NA, color = "orange") Cheers. Created on 2021-11-08 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.2 (2021-11-01)
#> os Ubuntu 20.04.3 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/Guayaquil
#> date 2021-11-08
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> abind * 1.4-5 2016-07-21 [2] CRAN (R 4.0.2)
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.2)
#> backports 1.2.1 2020-12-09 [2] CRAN (R 4.0.3)
#> class 7.3-19 2021-05-03 [4] CRAN (R 4.0.5)
#> classInt 0.4-3 2020-04-07 [2] CRAN (R 4.0.2)
#> cli 3.0.1 2021-07-17 [2] CRAN (R 4.1.0)
#> colorspace 2.0-2 2021-06-24 [2] CRAN (R 4.1.0)
#> crayon 1.4.1 2021-02-08 [2] CRAN (R 4.0.4)
#> curl 4.3.2 2021-06-23 [2] CRAN (R 4.1.0)
#> DBI 1.1.1 2021-01-15 [2] CRAN (R 4.0.3)
#> digest 0.6.28 2021-09-23 [2] CRAN (R 4.1.1)
#> dplyr 1.0.7 2021-06-18 [2] CRAN (R 4.1.0)
#> e1071 1.7-9 2021-09-16 [2] CRAN (R 4.1.1)
#> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.0.5)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.2)
#> fansi 0.5.0 2021-05-25 [2] CRAN (R 4.1.0)
#> farver 2.1.0 2021-02-28 [2] CRAN (R 4.0.5)
#> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.3)
#> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.3)
#> ggplot2 * 3.3.5 2021-06-25 [2] CRAN (R 4.1.0)
#> glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.2)
#> highr 0.9 2021-04-16 [2] CRAN (R 4.0.5)
#> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1)
#> httr 1.4.2 2020-07-20 [2] CRAN (R 4.0.2)
#> KernSmooth 2.23-20 2021-05-03 [4] CRAN (R 4.0.5)
#> knitr 1.36 2021-09-29 [2] CRAN (R 4.1.1)
#> labeling 0.4.2 2020-10-20 [2] CRAN (R 4.0.3)
#> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1)
#> lwgeom 0.2-8 2021-10-06 [2] CRAN (R 4.1.1)
#> magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.0.3)
#> mime 0.12 2021-09-28 [2] CRAN (R 4.1.1)
#> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.2)
#> pillar 1.6.4 2021-10-18 [2] CRAN (R 4.1.1)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.2)
#> proxy 0.4-26 2021-06-07 [2] CRAN (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.2)
#> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.0.5)
#> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.0.3)
#> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.0.3)
#> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1)
#> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1)
#> Rcpp 1.0.7 2021-07-07 [2] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1)
#> rlang 0.4.12 2021-10-18 [2] CRAN (R 4.1.1)
#> rmarkdown 2.11 2021-09-14 [2] CRAN (R 4.1.1)
#> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.3)
#> s2 1.0.7 2021-09-28 [2] CRAN (R 4.1.1)
#> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.5)
#> sf * 1.0-3 2021-10-07 [2] CRAN (R 4.1.1)
#> stars * 0.5-3 2021-06-08 [2] CRAN (R 4.1.1)
#> stringi 1.7.5 2021-10-04 [2] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.2)
#> styler 1.6.2 2021-09-23 [2] CRAN (R 4.1.1)
#> tibble 3.1.5 2021-09-30 [2] CRAN (R 4.1.1)
#> tidyselect 1.1.1 2021-04-30 [2] CRAN (R 4.0.5)
#> units 0.7-2 2021-06-08 [2] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.0.5)
#> withr 2.4.2 2021-04-18 [2] CRAN (R 4.0.5)
#> wk 0.5.0 2021-07-13 [2] CRAN (R 4.1.0)
#> xfun 0.27 2021-10-18 [2] CRAN (R 4.1.1)
#> xml2 1.3.2 2020-04-23 [2] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.2)
#>
#> [1] /home/gabo/R/x86_64-pc-linux-gnu-library/4.1
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library |
Thanks for this Gabo. This does indeed work, and I'm closing it as such. However, trying to run it with
I presume the error is related to: dkahle/ggmap#160 and dkahle/ggmap#162, however I've tried the solutions to these, with no success. I can't work out what the
But not when not transforming:
suggesting the
Gives the "coordinate system..." warning, and plots, but plots nothing. This seems super weird given I suspect I'll just have to add this onto the existing ggmap issue above, but I figured I'd share it with you in case you had any experience/ideas. Cheers! |
Hi folks,
I can plot my
stars
object inggplot
&ggmap
fine as a surface usinggeom_stars
.I'm trying to plot that same object as contours, and it's causing issues:
All_Rasters_Scales.asc
Is fine.
(same error for
ggmap
&ggplot
opening calls). I've seen various help online relating to R profiles' default themes, but I've not edited mine ever. Also this fails on those 2 lines, i.e. beforetheme
is called.The advice in the 'See Also' section of
st_contour
is:But:
lemons.sf <- st_as_sf(lemons.ras, as_points = FALSE, merge = TRUE)
If true, this suggests that in Adriano's table, only the bottom option is available ("POLYGONS, not merged").
According to
getGDALVersionInfo()
is have "GDAL 3.2.2, released 2021/03/05"Thanks in advance.
The text was updated successfully, but these errors were encountered: