r-tmap / tmap-book

A book on elegant and informative maps with the tmap package
https://r-tmap.github.io
Other
32 stars 5 forks source link

Two questions related to shapes #15

Open Nowosad opened 3 years ago

Nowosad commented 3 years ago

@mtennekes two open questions:

  1. Shapes for symbols: they work for both categorical and sequential data. However, should they work for sequential data?
  2. Shapes (lty) for lines: right now it is only possible to set one line type for all of the data. Would it be possible to allow to provide a categorical variable here?
library(tmap)
data("rivers", package = "tmap")
data("metro", package = "tmap")
set.seed(222)
metro2 = metro[sample(1:nrow(metro), 30), ]
set.seed(231)
metro2$group = as.character(sample(1:3, size = nrow(metro2), replace = TRUE))

# 1 -----------------------------------------------------------------------
# works
tm_shape(metro2) +
  tm_symbols(shape = "group")
#> Linking to GEOS 3.8.1, GDAL 3.0.4, PROJ 6.3.2

# also works - but should it?
tm_shape(metro2) +
  tm_symbols(shape = "pop1950")
#> Warning: Not enough symbol shapes available. Shapes will be re-used.

# 2 -----------------------------------------------------------------------
# works
tm_shape(rivers) + 
  tm_lines(lty = 2)

# does not work
tm_shape(rivers) + 
  tm_lines(lty = "type")
#> Error in grid.Call.graphics(C_lines, x$x, x$y, index, x$arrow): invalid hex digit in 'color' or 'lty'

Created on 2020-11-10 by the reprex package (v0.3.0)

mtennekes commented 3 years ago

This is something to look at for v4