1

I have generated a map showing the intensity of burglaries that have occurred on a street segment. I have used the tmap package from R to generate the desired street-level map. The codes are as follows:

   map.burglary =  tm_shape(street.crime.rates.lines) + 
                   tm_lines(col = "b_rates",
                            style = "fixed", 
                            breaks = c(0, 1, 10, 20, 50, 500),
                            labels = c("<1.0", "1.0-9.9", "10.0-19.9","20.0", 49.9", "50.0+"),
                            textNA = "Unavailable",
                            colorNA = "gray87",
                            title.col = c("Burglary (per 10 households)")) +
                   tm_compass(type = "8star", position = c("right","top")) +
                   tm_scale_bar(breaks = c(0, 0.25, 0.5, 0.75, 1)) +
                   tm_layout(frame = TRUE, legend.title.size = 0.8, legend.outside = TRUE, legend.outside.position = "right")
    map.burglary

The resulting output:

enter image description here

I want to increase the line thickness of each line as the intensity of burglaries represented on the map becomes larger. I want this detail to be reflected in the map and legends. Does anyone know how to code this in R using the tmap package?

2
  • 1
    Does the standard lwd argument not work? – Jeffrey Evans Jul 24 '18 at 15:26
  • It works, but it increases the size of all lines. I want to assign different lwd's that are specify to each of the lines that are represented in the map (and legends). If I try something like ... lwd = c(1, 1.3, 1.5, 1.7, 2),... in the tm_lines function it literally splits the image into 5 separate maps which is weird. – The-PhD-Gamer Jul 24 '18 at 15:56
2

You have to give the name of the variable in the thing being plotted, not the values. For example with data like this:

> m@data
          name            type scalerank strokelwd
5  Mississippi Lake Centerline         5       2.0
6  Mississippi Lake Centerline         5       2.5
7  Mississippi           River         5       1.5

you'd use:

tm_shape(m) + tm_lines(lwd="strokelwd")

producing:

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.