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, ...)

Arguments

x

see cut

breaks

see cut

...

see cut

Value

an array or matrix with a levels attribute; see details

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.

Examples

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 1 349 288776 28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [x] #> y 1 352 9120761 -28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [y] #> band 1 6 NA NA NA NA NULL
cut(x[,,,1], c(0, 50, 100, 255))
#> 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 1 349 288776 28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [x] #> y 1 352 9120761 -28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [y] #> band 1 1 NA NA NA NA NULL
plot(cut(x[,,,1], c(0, 50, 100, 255)))
tif = 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 1 349 288776 28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [x] #> y 1 352 9120761 -28.5 PROJCS["UTM Zone 25, Sout... FALSE NULL [y] #> band 1 6 NA NA NA NA NULL
plot(x1_cut[,,,c(3,6)]) # propagates through [ and plot