Skip to content

Commit

Permalink
to address #16 using solution from rstudio/learnr#529 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
andysouth committed May 26, 2021
1 parent e0c59cc commit 42def21
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions inst/tutorials/afrilearnr-crash-course/afrilearnr-crash-course.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ sf::st_crs(africontinent) <- 4326

`tmap` uses static 'plot' mode by default. To make these plots interactive, copy & paste `tmap_mode('view')` above the code below & press `Run Code`.

```{r tmap-vector-raster-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(1)
```

```{r tmap-vector-raster, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
tmap::tm_shape(afripop2020) +
Expand All @@ -76,6 +83,13 @@ tm_legend(show = FALSE)

`tmap` uses static 'plot' mode by default. To make these plots interactive, copy & paste `tmap_mode('view')` above the code below & press `Run Code`.

```{r tmap-colour-polygons-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(2)
```

```{r tmap-colour-polygons, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
Expand Down Expand Up @@ -113,6 +127,13 @@ ggplot(africountries) +

## mapview : interactive point data

```{r mapview-points-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
#tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(3)
```

```{r mapview-points, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
mapview(africapitals,
Expand All @@ -126,6 +147,13 @@ mapview(africapitals,

Using `list(1,2)` to pass two layers and respective arguments.

```{r mapview-points-lines-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
#tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(4)
```

```{r mapview-points-lines, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
mapview(list(africapitals, afrihighway),
Expand All @@ -141,6 +169,13 @@ mapview(list(africapitals, afrihighway),

Rasters are displayed semi-transparent by default so base layers including place names are visible. Population density data are often highly skewed with rare high values meaning that most variation gets hidden when using default data breaks between colours. Specifying near logarithmic breaks using `at` below makes patterns clearer.

```{r mapview-raster-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
#tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(5)
```

```{r mapview-raster, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
mapview(afripop2020,
Expand All @@ -154,6 +189,12 @@ Note that previously this failed on shinyapps : package 'rgdal' is not available

We can select one row from `africountries` in `afrilearndata` to allow us to display a country, using the `bbox` argument in tmap, the `ext` argument allows us to extend the bbox a little.

```{r mapview-one-country-setup}
# to avoid issues with interactive maps https://github.com/rstudio/learnr/issues/529
# IdSeed must be set to be unique in the Rmd, even for mode('plot') to allow user to change
#tmap_mode("plot")
htmlwidgets::setWidgetIdSeed(6)
```

```{r mapview-one-country, exercise = TRUE, exercise.eval = TRUE, message = FALSE, warning = FALSE, exercise.setup='libraries'}
Expand Down

0 comments on commit 42def21

Please sign in to comment.