cut methods for stars objects
# S3 method for array cut(x, breaks, ...) # S3 method for matrix cut(x, breaks, ...) # S3 method for stars cut(x, breaks, ...)
x | see cut |
---|---|
breaks | see cut |
... | see cut |
an array or matrix with a levels
attribute; see details
R's factor
only works for vectors, not for arrays or matrices. This is a work-around (or hack?) to keep the factor levels generated by cut
and use them in plots.
tif = system.file("tif/L7_ETMs.tif", package = "stars") x = read_stars(tif) cut(x, c(0, 50, 100, 255))#> stars object with 3 dimensions and 1 attribute #> attribute(s): #> L7_ETMs.tif #> (0,50] :156060 #> (50,100] :503764 #> (100,255]: 77264 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 349 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x] #> y 1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y] #> band 1 6 NA NA NA NA NULL#> stars object with 3 dimensions and 1 attribute #> attribute(s): #> L7_ETMs.tif #> (0,50] : 1 #> (50,100] :117134 #> (100,255]: 5713 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 349 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x] #> y 1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y] #> band 1 1 NA NA NA NA NULLtif = system.file("tif/L7_ETMs.tif", package = "stars") x1 = read_stars(tif) (x1_cut = cut(x1, breaks = c(0, 50, 100, Inf))) # shows factor in summary#> stars object with 3 dimensions and 1 attribute #> attribute(s): #> L7_ETMs.tif #> (0,50] :156060 #> (50,100] :503764 #> (100,Inf]: 77264 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 349 288776 28.5 UTM Zone 25, Southern Hem... FALSE NULL [x] #> y 1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE NULL [y] #> band 1 6 NA NA NA NA NULL