[R-sig-Geo] unexpected attribute plotting with sf polygons
Waichler, Scott R
Scott@W@|ch|er @end|ng |rom pnn|@gov
Fri Sep 27 22:08:45 CEST 2024
Thank you for this. I think my software may be too old and has caused the problem. I am running R version 4.2.2 Patched (2023-01-29 r83721) and sf_1.0-9 . I will get it updated.
Thanks,
Scott
________________________________
From: Zivan Karaman <zivan.karaman using gmail.com>
Sent: Friday, September 27, 2024 12:47 PM
To: Waichler, Scott R <Scott.Waichler using pnnl.gov>
Cc: r-sig-geo using r-project.org <r-sig-geo using r-project.org>; edzer.pebesma using uni-muenster.de <edzer.pebesma using uni-muenster.de>
Subject: Re: [R-sig-Geo] unexpected attribute plotting with sf polygons
When I run your code I get Time1 in one color and Time2 in another color, as expected.
[image.png]
On Fri, Sep 27, 2024 at 8:23 PM Waichler, Scott R <Scott.Waichler using pnnl.gov<mailto:Scott.Waichler using pnnl.gov>> wrote:
Thanks for the comments, but it's still not working. The version below uses vectors instead of a matrix for the attributes, but it's still making two plots all of the same color. Time1 should be one color, Time2 should be the other. As should be clear from my attribute names, I am trying to use the lattice-like paneling capability to represent values at different times of the same variable.
my.text <-
c("POLYGON ((0 2.69, 4.483057 2.86, 4.483057 2.76, 0 2.59, 0 2.69))",
"POLYGON ((0 2.59, 4.483057 2.76, 4.483057 2.26, 0 2.09, 0 2.59))",
"POLYGON ((0 2.09, 4.483057 2.26, 4.483057 1.26, 0 1.09, 0 2.09))",
"POLYGON ((0 1.09, 4.483057 1.26, 4.483057 -0.74, 0 -0.91, 0 1.09))")
my.poly <- st_as_sfc(my.text)
my.poly2 <- st_sf(Time1 = rep(1,4), Time2 = rep(2,4), geom = my.poly)
plot(my.poly2, breaks = c(0.5, 1.5, 2.5))
--Scott Waichler
________________________________
From: Zivan Karaman <zivan.karaman using gmail.com<mailto:zivan.karaman using gmail.com>>
Sent: Friday, September 27, 2024 9:37 AM
To: Waichler, Scott R <Scott.Waichler using pnnl.gov<mailto:Scott.Waichler using pnnl.gov>>
Cc: r-sig-geo using r-project.org<mailto:r-sig-geo using r-project.org> <r-sig-geo using r-project.org<mailto:r-sig-geo using r-project.org>>
Subject: Re: [R-sig-Geo] unexpected attribute plotting with sf polygons
Check twice before you click! This email originated from outside PNNL.
You have defined two attributes that are constant across your geometries, so they are shown in the same color.
The code `mat <- matrix(c(rep(1, 2), rep(2, 2)), byrow=FALSE, ncol=1)` will define one attribute with two distinct values that will be shown in two colors.
Hope this helps!
On Fri, Sep 27, 2024 at 4:37 PM Waichler, Scott R via R-sig-Geo <r-sig-geo using r-project.org<mailto:r-sig-geo using r-project.org>> wrote:
Hi, When I plot the "sf" and "data.frame" object my.poly2 below, all of the polygons are the same color, despite my setting two different values for the Attribute. What have I done wrong?
my.text <-
c("POLYGON ((0 2.69, 4.483057 2.86, 4.483057 2.76, 0 2.59, 0 2.69))",
"POLYGON ((0 2.59, 4.483057 2.76, 4.483057 2.26, 0 2.09, 0 2.59))",
"POLYGON ((0 2.09, 4.483057 2.26, 4.483057 1.26, 0 1.09, 0 2.09))",
"POLYGON ((0 1.09, 4.483057 1.26, 4.483057 -0.74, 0 -0.91, 0 1.09))")
my.poly <- st_as_sfc(my.text)
mat <- matrix(c(rep(1, 4), rep(2, 4)), byrow=F, ncol=2)
my.poly2 <- st_sf(Attribute = mat, geom = my.poly)
plot(my.poly2, breaks = c(0.5, 1.5, 2.5))
Thank you,
Scott Waichler, PhD
Pacific Northwest National Lab
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo using r-project.org<mailto:R-sig-Geo using r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20240927/17e4463d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 22014 bytes
Desc: image.png
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20240927/17e4463d/attachment.png>
More information about the R-sig-Geo
mailing list