Skip to content

Commit

Permalink
library cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowosad committed Oct 26, 2017
1 parent e9ddf06 commit ab0854c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
1 change: 0 additions & 1 deletion 03-attribute-operations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ The following code recreates the raster dataset used in section \@ref(raster-cla
This demonstrates how the `raster()` function works to create an example raster named `elev` (representing elevations).

```{r, message=FALSE}
library(raster)
elev = raster(nrow = 6, ncol = 6, res = 0.5,
xmn = -1.5, xmx = 1.5, ymn = -1.5, ymx = 1.5,
vals = 1:36)
Expand Down
13 changes: 4 additions & 9 deletions 05-read-write-plot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ library(tidyverse)
library(sf)
library(spData)
library(raster)
library(tmap)
library(mapview)
```

## Introduction
Expand Down Expand Up @@ -219,7 +221,6 @@ In most cases, as with the ESRI Shapefile (`.shp`) or the `GeoPackage` format (`
`st_read()` guesses the driver based on the file extension, as illustrated for a `.gpkg` file below:

```{r}
library(sf)
vector_filepath = system.file("shapes/world.gpkg", package = "spData")
world = st_read(vector_filepath)
```
Expand Down Expand Up @@ -268,8 +269,6 @@ Similar to vector data, raster data comes in many file formats with some of them
**raster**'s `raster()` command reads in a single layer.

```{r, message=FALSE}
library(raster)
library(spDataLarge)
raster_filepath = system.file("raster/srtm.tif", package = "spDataLarge")
single_layer = raster(raster_filepath)
```
Expand Down Expand Up @@ -355,7 +354,6 @@ This can be done by specifying `GEOMETRY` inside of `layer_options`.
It could be either `AS_XY` for simple point datasets (it creates two new columns for coordinates) or `AS_WKT` for more complex spatial data (one new column is created which contains the well-known-text representation of spatial objects).

```{r, eval=FALSE}
library(spData)
st_write(cycle_hire_xy, "cycle_hire_xy.csv", layer_options = "GEOMETRY=AS_XY")
st_write(world_wkt, "world_wkt.csv", layer_options = "GEOMETRY=AS_WKT")
```
Expand Down Expand Up @@ -435,7 +433,6 @@ For example, the **tmap** package has the `save_tmap()` function.
You can save a `tmap` object to different graphic formats by specifying the object name and a file path to a new graphic file.

```{r, eval=FALSE}
library(tmap)
tmap_obj = tm_shape(world) +
tm_polygons(col = "lifeExp")
save_tmap(tm = tmap_obj, filename = "lifeExp_tmap.png")
Expand All @@ -446,14 +443,12 @@ save_tmap(tm = tmap_obj, filename = "lifeExp_tmap.png")
<!-- a = plot(world["lifeExp"]) -->
<!-- ``` -->

On the other hand, on can save interactive maps as an HTML file using the `saveWidget()` function from the `htmlwidgets` package:
On the other hand, on can save interactive maps created in the `mapview` package as an HTML file or image using the `mapshot()` function:

<!-- example doesn't work, problem with colors I guess -->
```{r, eval=FALSE}
library(mapview)
library(htmlwidgets)
mapview_obj = mapview(world, zcol = "lifeExp", legend = TRUE)
saveWidget(mapview_obj, file = "my_interactive_map.html")
mapshot(mapview_obj, file = "my_interactive_map.html")
```

## Exercises
Expand Down

0 comments on commit ab0854c

Please sign in to comment.