[R-sig-Geo] unexpected attribute plotting with sf polygons

Zivan Karaman z|v@n@k@r@m@n @end|ng |rom gm@||@com
Fri Sep 27 18:37:48 CEST 2024


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> 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
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list