Questions tagged [tmap]

tmap is an actively maintained open-source R-library for drawing thematic maps, written by Martijn Tennekes. The API is based on the Layered Grammar of Graphics, and resembles the syntax of ggplot2, a popular R-library for drawing charts.

tmap is an actively maintained open-source R-library for drawing thematic maps, written by Martijn Tennekes. The API is based on A Layered Grammar of Graphics by Hadley Wickham and resembles the syntax of , a popular R-library for drawing charts.

Repositories

Vignette

Presentation

Other resources

487 questions
3
votes
2 answers

Is it possible to exclude areas of maps made with sf and tmap?

I have created a map of Europe using a shape file downloaded from Eurostat. The file also includes several European administered areas such as French Guiana. I would like to exclude these areas. Is that possible? Here is a picture of the map, and…
sard
  • 41
  • 3
3
votes
1 answer

R - Multiple compasses in tmap

Is it possible to include more than one tm_compass() on a map created by tmap? I know it's probably unlikely that you'd need to, but say you wanted to show off the different compass types. Using nz from the spData package I tried adding each new…
hugh-allan
  • 1,170
  • 5
  • 16
3
votes
2 answers

animation of vehicle from A to B and then B to A along the route (with some wait time at B)

Below is an example of animating vehicle moving from A to B. [solved by @mrhellmann here, there are solutions also available] I want to animate vehicle moving from A to B and then wait at B for sometime and then return to A. Below is the code which…
SiH
  • 1,378
  • 4
  • 18
3
votes
1 answer

Loading some packages affects random number generation?

I found that loading some packages will affect random number generation in R. The problem can be reproduced as follows. (1) Open a new R session. (My case: R 4.x + RStudio) (2) Execute the following…
Frank KKK
  • 313
  • 1
  • 2
  • 6
3
votes
1 answer

Combine tmap and ggplot

I am trying to combine test1, a map made with tmap, with test2, a plot made with ggplot2, using cowplot::plot_grid. library(ggplot2) library(tmap) library(cowplot) library(ggplotify) test2 <-ggplot(iris, aes(Sepal.Length, Sepal.Width, color =…
Jana
  • 33
  • 4
3
votes
1 answer

How to arrange the position of this legend

As shown in the map below, how can I place the legend to the last cell in the grid? The code I used is psp1 <- tm_shape(province) + tm_borders(col = 'black') + tm_shape(county) + tm_polygons(col = 'estimate', title = 'Changes in %', style…
Yabin Da
  • 553
  • 5
  • 11
3
votes
2 answers

How can I wrap long text strings in tmap HTML polygon popups or fixed widths? Can tmap recognize line breaks?

I am using the tmap package (v. 3.0 and I also tried v. 3.2) in R to make an HTML map. I have a spatial polygon of both numeric and character text fields. In a few of my text fields, I have a list of items, which are semi-colon (;) separated. For…
Tia
  • 31
  • 2
3
votes
1 answer

How can I place the legend below the facets using tmap in R?

Here is a reproducible example library(tmap) data("World") tm_shape(World) + tm_polygons("pop_est", style = "cont", legend.is.portrait=FALSE) + tm_facets("continent") + tm_layout(legend.position = c("left", "bottom"), main.title =…
Robin Lindström
  • 622
  • 4
  • 15
3
votes
0 answers

How do I handle legend boxes with tmap library?

Please, consider the following example: library(tmap) data("World") tm_shape(World) + tm_polygons("HPI") This gives me the following map: My problem is the legend. The legend boxes that show the colors are squares that are directly next to each…
coleuch
  • 31
  • 5
3
votes
0 answers

R tmap giving slightly different extents despite setting bbox

I am trying to export a number of plots using R's tmap package. I am quite new to using tmap. I have set up two maps that should cover a similar extent and I am using the bbox argument of tm_shape with the intent of forcing exactly the same…
Sarah
  • 3,022
  • 1
  • 19
  • 40
3
votes
1 answer

Why is a Spatial Data Frame obtained from OSM/Nominatim invalid?

I want to get plottable spatial (boundary/polygon) data from OpenStreetMap using the nominatim R package. The nominatim::osm_search_spatial request seems to work successfully but the resulting data, despite being found as a…
Francis Barton
  • 129
  • 2
  • 16
3
votes
2 answers

The boundary lines between two polygons seems to be different than the outline when plotted using the tmap package

I am plotting the boundary of several polygons using the tmap package. The following code is a basic example. library(sf) library(tmap) nc <- st_read(system.file("shape/nc.shp", package = "sf")) tm_shape(nc) + tm_borders() This looks good.…
www
  • 38,575
  • 12
  • 48
  • 84
3
votes
1 answer

How do I customize my color range for my tmap plot in R?

I want to plot a map showing crime frequency. I run the command: tm_shape(trinidad) + tm_polygons("Crime_Total", palette = "Reds", colorNA = NULL, title = "Crime Frequency") and obtain this result I have a few issues with this plot, though. As…
Outlier
  • 417
  • 2
  • 10
3
votes
1 answer

Plotting legend only in tmap

I have a crowded map I've generated using the tmap library, I've turned the legend off with the argument legend.show = FALSE in the tm_layout() function. What I want to know is the following: is there a way to generate a legend for this map on its…
damo
  • 463
  • 4
  • 14
3
votes
0 answers

Combining tmap with shiny in R studio

I am trying to create a map in the mainPanel and two buttons in the sidebarPanel. I have two maps and I want them to appear in the mainPanel after pressing a specific button. These maps work outside shiny. ui <- fluidPage( …
Angela
  • 31
  • 2