I use the tmap
package. I plot a map with the qtm()
function but the legend is not displayed. Indeed, I understand that the legend is automatically display, unless you specify to hide it.
I also try to use a work-around with the tm_add_legend()
but it doesn't work.
Here is my code :
library(sp) ; library(rgdal) ; library(rgeos) ;
library(tmap) ; library(maptools)
Directory <- ""
MapFrance <- readOGR(dsn = paste0(Directory, "Departements"), layer = "DEPARTEMENT")
MapFrance@data$Score <- round(runif(96, min = 1, max = 10), 0)
brk <- c(1, 2.5, 5, 7.5, 10)
ClassScore <- classIntervals(MapFrance@data$Score, style = "fixed", fixedBreaks = brk)
Palette <- brewer.pal(length(brk) - 1, "Greens")
MapFrance@data$Categorie <- as.character(cut(MapFrance@data$Score,
breaks = ClassScore$brks,
labels = Palette,
include.lowest = TRUE))
ExampleData <- MapFrance[MapFrance$CODE_REG == "11", ]
qtm(ExampleData, fill = "Categorie", text = "CODE_DEPT", text.size = "AREA", style = "gray",
text.root = 5, fill.title = "Opinion scale")
And a link to the geographic data : https://drive.google.com/file/d/1wksMnkufQPdOfSbhWoZbPKMqlcLcll_j