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

terra: plet() to plot a quantitative field of SpatVector #1177

Closed
aloboa opened this issue May 30, 2023 · 2 comments
Closed

terra: plet() to plot a quantitative field of SpatVector #1177

aloboa opened this issue May 30, 2023 · 2 comments

Comments

@aloboa
Copy link

aloboa commented May 30, 2023

(see also in https://stackoverflow.com/questions/76359833/terra-plet-to-plot-a-quantitative-field-of-spatvector)

I have problems producing reasonable plots of quantitative fields in SpatVector objects.
Using data from the example on the help page:

v <- vect(system.file("ex/lux.shp", package="terra"))
plet(v, "POP", tiles="")

enter image description here
Note the color scale is not appropriate for a continuous variable and the legend is not ordered.

r <- rast(system.file("ex/elev.tif", package="terra"))
#correct plot:
plet(r, tiles="")

enter image description here

#but
rp <- as.points(r)
plet(rp, "elevation", tiles="")

enter image description here

It looks like the quantitative field is plotted as if it were qualitative, but
I do not see specific options in the parameter list.

@rhijmans
Copy link
Member

Thanks, I believe this now works. The choice of legend is based on the data (character or numeric), and for numeric how many unique values there are. You can also set the legend type with argument "type". Also see arguments "breaks" and "breakby"

@aloboa
Copy link
Author

aloboa commented Jun 13, 2023

Yes, it does work, thank you:

v <- vect(system.file("ex/lux.shp", package="terra"))
plet(v, "POP", tiles="")

image

Please consider adding this example to the help page.

Regarding breaks and breakby, I observe they do not exist for spatial raster objects.

         plet(r, tiles="")
         plet(r, tiles="", breaks=0:100)
         Error in .local(x, ...) : unused argument (breaks = 0:100)
         plet(r, tiles="", breakby="eqint")
         Error in .local(x, ...) : unused argument (breakby = "eqint")

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

No branches or pull requests

2 participants