r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
864 stars 121 forks source link

tm_chart implemented (histogram, box plot, etc.); please review #842

Closed mtennekes closed 4 months ago

mtennekes commented 7 months ago
## numerical variable

tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_intervals(), 
                 fill.chart = tm_chart_histogram())


tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_continuous(), 
                 fill.chart = tm_chart_histogram(position = tm_pos_out("center", "bottom"), width = 30))
#> Warning: Some legend items or map compoments do not fit well (e.g. due to the
#> specified font size).


tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_intervals(), 
                 fill.chart = tm_chart_donut())


tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_intervals(), 
                 fill.chart = tm_chart_box())


tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_intervals(), 
                 fill.chart = tm_chart_violin())


# with additional ggplot2 code
require(ggplot2)
#> Loading required package: ggplot2
tm_shape(World) + 
    tm_polygons ("HPI", 
                 fill.scale = tm_scale_intervals(), 
                 fill.chart = tm_chart_bar(extra.ggplot2 = theme(panel.grid.major.y = element_line(colour = "red"))))


tm_shape(land) +
    tm_raster("trees",
              col.chart = tm_chart_histogram())


## categorical variable
tm_shape(World) + 
    tm_polygons ("economy", 
                 fill.scale = tm_scale_categorical(), 
                 fill.chart = tm_chart_bar())


tm_shape(World) + 
    tm_polygons ("economy", 
                 fill.scale = tm_scale_categorical(), 
                 fill.chart = tm_chart_donut())

Created on 2024-03-07 with reprex v2.1.0

LenLon commented 7 months ago

Antarctica is a developing region? I had no idea :-D

mtennekes commented 7 months ago

Antarctica is a developing region? I had no idea :-D

Me neither, but apparently that's what in the data is.

However, this brings up a question that comes back every now and then: in which CRS should the tmap example data be stored? In tmap3, World was in Eckert IV, but in tmap4 (so far) World is in 4326 (WGS84). Do we need to implement a "smart" automatic CRS, that is optimised for that bounding box? @Nowosad I thought this has been discussed, but I couldn't find the related issue.

Nowosad commented 7 months ago

@mtennekes I think you are looking for this discussion -- https://github.com/r-tmap/tmap/issues/457