inst/doc/stars3.R

## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, dev = "png")
ev = TRUE
knitr::opts_chunk$set(fig.height = 4.5)
knitr::opts_chunk$set(fig.width = 6)

## -----------------------------------------------------------------------------
library(stars)
library(dplyr)

## -----------------------------------------------------------------------------
methods(class = "stars")

## -----------------------------------------------------------------------------
system.file("tif/L7_ETMs.tif", package = "stars") %>%
	read_stars -> x
x

## -----------------------------------------------------------------------------
x %>% slice(band, 6) -> x6
x6

## -----------------------------------------------------------------------------
x %>% filter(x > 289000, x < 291000, band > 3) -> x7
x7

## -----------------------------------------------------------------------------
x %>% pull(1) -> x8
class(x8)
dim(x8)

## -----------------------------------------------------------------------------
x %>% mutate(band2 = 2 * L7_ETMs.tif) -> x2 
x2

## -----------------------------------------------------------------------------
x2 %>% select(band2) -> x9
x9

## -----------------------------------------------------------------------------
library(ggplot2)
library(viridis)
ggplot() + 
  geom_stars(data = x) +
  coord_equal() +
  facet_wrap(~band) +
  theme_void() +
  scale_fill_viridis() +
  scale_x_discrete(expand = c(0, 0)) +
  scale_y_discrete(expand = c(0, 0))

Try the stars package in your browser

Any scripts or data that you put into this service are public.

stars documentation built on Sept. 11, 2023, 5:10 p.m.