https://github.com/r-tmap/tmap
R package for thematic maps
https://github.com/r-tmap/tmap
choropleth-maps maps r spatial thematic-maps visualisation
Last synced: 5 days ago
JSON representation
R package for thematic maps
- Host: GitHub
- URL: https://github.com/r-tmap/tmap
- Owner: r-tmap
- License: gpl-3.0
- Created: 2013-11-25T10:16:24.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2025-04-10T16:12:15.000Z (7 days ago)
- Last Synced: 2025-04-10T16:50:41.741Z (7 days ago)
- Topics: choropleth-maps, maps, r, spatial, thematic-maps, visualisation
- Language: R
- Homepage: https://r-tmap.github.io/tmap
- Size: 715 MB
- Stars: 879
- Watchers: 27
- Forks: 123
- Open Issues: 63
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - r-tmap/tmap - R package for thematic maps (R)
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
out.width = "100%",
dpi = 300,
fig.width = 7.2916667,
comment = "#>",
fig.path = "man/figures/README-"
)
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)
})
```# tmap: thematic maps in R
[](https://github.com/r-tmap/tmap/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/r-tmap/tmap?branch=master)
[](https://cran.r-project.org/package=tmap)
[](https://cran.r-project.org/web/checks/check_results_tmap.html)
[](https://www.r-pkg.org:443/pkg/tmap)
[](https://www.gnu.org/licenses/gpl-3.0.html)
[](https://r-tmap.r-universe.dev/tmap)**tmap** is an R package for drawing thematic maps. The API is based on [*A Layered Grammar of Graphics*][4] and resembles the syntax of [**ggplot2**][3], a popular R-library for drawing charts.
## Installation
Installation of **tmap** (version 4) is straightforward:
```{r eval=FALSE}
install.packages("tmap")
```The old version of **tmap** (version 3) is available in the [CRAN archive](https://cran.r-project.org/src/contrib/Archive/tmap/),
but we recommend moving to the new version 4.### Development version
The development version can be installed from the GitHub repository using
`remotes` and `pak` packages or from the [R-universe repository](https://r-tmap.r-universe.dev/tmap).```{r eval=FALSE}
# install.packages("remotes")
remotes::install_github("r-tmap/tmap")# install.packages("pak")
pak::pak("r-tmap/tmap")# Or from r-universe
install.packages("tmap", repos = c("https://r-tmap.r-universe.dev", "https://cloud.r-project.org"))
```For Linux and macOS users who are new to working with spatial data in R, this may fail since additional (non-R) libraries are required (which are automatically installed for Windows users).
**Windows**
No additional installation required.**Linux (Ubuntu)**
See https://geocompx.org/post/2020/installing-r-spatial-packages-linux/. Please address installation issues in this [issue](https://github.com/r-tmap/tmap/issues/150).**macOS**
See https://www.kyngchaos.com/. Please address installation issues in this [issue](https://github.com/r-tmap/tmap/issues/149).## Getting started
```{r echo=FALSE, message=FALSE}
library(tmap)
```Plot a World map of the happy planet index (HPI) per country.
The object `World` is an example spatial data (`sf`) object that is contained in **tmap**:```{r fig.height=3.5, message=FALSE}
tm_shape(World) +
tm_polygons(fill = "HPI")
```This map can be enhanced in several ways.
For instance:```{r fig.height=4.5}
tm_shape(World, crs = "+proj=robin") +
tm_polygons(fill = "HPI",
fill.scale = tm_scale_continuous(values = "matplotlib.rd_yl_bu"),
fill.legend = tm_legend(title = "Happy Planet Index",
orientation = "landscape",
frame = FALSE)
)
```## Additional Resources for Learning **tmap**
For more in-depth learning on the **tmap** package, refer to the following resources:
- **Book Chapter:** [Geocomputation with R](https://r.geocompx.org/) includes a chapter on [Making Maps with R](https://r.geocompx.org/adv-map), which covers **tmap**.
- **Official Vignettes:** A collection of vignettes at [r-tmap.github.io](https://r-tmap.github.io/tmap/articles/) covers both basic and advanced topics with examples.
- **Work-in-Progress Book:** *Elegant and Informative Maps with tmap* is an upcoming book available at [tmap.geocompx.org](https://tmap.geocompx.org/).These resources provide a solid foundation for working with **tmap** in R.
[3]: https://cran.r-project.org/package=ggplot2
[4]: https://vita.had.co.nz/papers/layered-grammar.pdf