When I run your code I get Time1 in one color and Time2 in another color, as expected. [image: image.png]
On Fri, Sep 27, 2024 at 8:23 PM Waichler, Scott R <scott.waich...@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.kara...@gmail.com> > *Sent:* Friday, September 27, 2024 9:37 AM > *To:* Waichler, Scott R <scott.waich...@pnnl.gov> > *Cc:* r-sig-geo@r-project.org <r-sig-geo@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@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@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > >
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo