library(stars)
## Loading required package: abind
## Loading required package: sf
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(ggplot2)

# 'stars' with two attributes
filename = system.file("tif/L7_ETMs.tif", package = "stars")
r = read_stars(filename)
names(r) = "refl"
r$refl2 = r$refl * 2
r
## stars object with 3 dimensions and 2 attributes
## attribute(s):
##      refl             refl2      
##  Min.   :  1.00   Min.   :  2.0  
##  1st Qu.: 54.00   1st Qu.:108.0  
##  Median : 69.00   Median :138.0  
##  Mean   : 68.91   Mean   :137.8  
##  3rd Qu.: 86.00   3rd Qu.:172.0  
##  Max.   :255.00   Max.   :510.0  
## dimension(s):
##      from  to  offset delta                       refsys point values    
## 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
# From attributes to dimension
r = st_redimension(r)
names(r) = "value"
r
## stars object with 4 dimensions and 1 attribute
## attribute(s), summary of first 1e+05 cells:
##      value       
##  Min.   : 47.00  
##  1st Qu.: 65.00  
##  Median : 76.00  
##  Mean   : 77.34  
##  3rd Qu.: 87.00  
##  Max.   :255.00  
## dimension(s):
##         from  to  offset delta                       refsys point       values
## x          1 349  288776  28.5 UTM Zone 25, Southern Hem... FALSE         NULL
## y          1 352 9120761 -28.5 UTM Zone 25, Southern Hem... FALSE         NULL
## band       1   6      NA    NA                           NA    NA         NULL
## new_dim    1   2      NA    NA                           NA    NA refl , refl2
##            
## x       [x]
## y       [y]
## band       
## new_dim
# Plot
ggplot() +
    geom_stars(data = r) +
    facet_grid(new_dim ~ band) +
    coord_equal()