knitr::opts_chunk$set( collapse = TRUE, out.width = "100%", dpi = 300, fig.width = 7.2916667, comment = "#>" ) hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines)==1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(more, x[lines], more) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) })
library(tmap) library(dplyr) library(sf) tmap_options(scale = 0.75)
We use a couple of spatial data objects contained in tmap: World_rivers
, land
and metro
.
tm_shape(land) + tm_raster(col = "cover") + #tm_shape(World) + # tm_borders() + tm_shape(World_rivers) + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = 0.2)) + tm_shape(metro) + tm_symbols(shape = 20, size = 0.6, fill = "white") + tm_symbols(shape = 20, size = 0.5, fill = "red") + tm_crs("+proj=eck4") + tm_layout(earth_boundary = TRUE, earth_boundary.lwd = 2, legend.show = FALSE, # option to disable all legends frame = FALSE, space.color = "white") + tm_title("Map of the World", position = tm_pos_out(cell.h = "center", cell.v = "top", pos.h = "center")) + tm_credits("Eckert IV projection", position = c("RIGHT", "BOTTOM"))
Note: upper case position spefications (last line) means tight to the right bottom corner
tmap_style("classic") tmap_last()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.