Skip to content

Commit

Permalink
Replace unique() with levels() for factors
Browse files Browse the repository at this point in the history
  • Loading branch information
cforgaci committed Jan 15, 2024
1 parent e7d2899 commit 88a1259
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions episodes/14-plot-raster-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ ggplot() +
geom_bar(data = DSM_TUD_df, aes(fct_elevation))
```

To see the cut-off values for the groups, we can ask for the unique values of `fct_elevation`:
To see the cut-off values for the groups, we can ask for the levels of `fct_elevation`:
```{r}
unique(DSM_TUD_df$fct_elevation)
levels(DSM_TUD_df$fct_elevation)
```

And we can get the count of values (that is, number of pixels) in each group using `dplyr`’s `count()` function:
Expand All @@ -76,7 +76,7 @@ custom_bins <- c(-10, 0, 5, 100)
DSM_TUD_df <- DSM_TUD_df %>%
mutate(fct_elevation_cb = cut(`tud-dsm-5m`, breaks = custom_bins))
unique(DSM_TUD_df$fct_elevation_cb)
levels(DSM_TUD_df$fct_elevation_cb)
```

::: callout
Expand Down Expand Up @@ -161,7 +161,7 @@ Create a plot of the TU Delft Digital Surface Model (`DSM_TUD`) that has:
DSM_TUD_df <- DSM_TUD_df %>%
mutate(fct_elevation_6 = cut(`tud-dsm-5m`, breaks = 6))
unique(DSM_TUD_df$fct_elevation_6)
levels(DSM_TUD_df$fct_elevation_6)
my_col <- terrain.colors(6)
Expand Down

0 comments on commit 88a1259

Please sign in to comment.