Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text labels that adapt their shape to the lines #279

Closed
hmeleiro opened this issue Feb 7, 2019 · 2 comments
Closed

text labels that adapt their shape to the lines #279

hmeleiro opened this issue Feb 7, 2019 · 2 comments
Labels

Comments

@hmeleiro
Copy link

hmeleiro commented Feb 7, 2019

I don't know if this is an issue but here it goes:

I'm trying to print a map of lines (streets) and want to visualize their labels (street names) in a way that they adapt to the shape of the line. I thought that the along.lines argument in the tm_text() function was going to do the job but it doesn't. I dont know if this is because is not the expected behaviour of along.lines = T or because I'm doing something wrong.

I first did this:

mapa <- tmap_mode(mode = "plot") +  
tm_shape(calles, name = "calles", bbox = b) + 
tm_lines(col = "black", alpha = 0.8) + 
tm_text(text = "NOMBRE", size = 0.6,  col = "black", fontfamily = "Roboto Condensed", along.lines = T, remove.overlap = T, shadow = T, overwrite.lines = T, auto.placement = T)
  
mapa

but got this error: Error: is.list(x) is not TRUE

So I did this, didn't get the error but achieved nothing:

calles <-  readOGR("~/Downloads/900YTOYWDW/call2017.shp")
calles <- calles[calles@data$CMUN == "079",]

mapa <- tmap_mode(mode = "plot") +  
tm_shape(calles, name = "calles", bbox = b) + tm_lines(col = "black", alpha = 0.8) +
tm_shape(calles, name = "nomcalles", bbox = b) + tm_text(text = "NOMBRE", size = 0.6, col = "black", fontfamily = "Roboto Condensed", along.lines = T, remove.overlap = T, shadow = T, overwrite.lines = T, auto.placement = T)

mapa

In the case that this is not the expected behaviour of along.lines, is there a way of achieving this with tmap()?

The shapefile I'm using can be downloaded here.

Thank you very much in advance.
Great package by the way!!

@mtennekes
Copy link
Member

Thanks for your question!

First, tmap_mode() should be used separately.

When I run this code

tmap_mode(mode = "plot")
calles2 <- calles[1:10,]
tm_shape(calles2, name = "calles") + 
tm_lines(col = "black", alpha = 0.8) + 
	tm_text(text = "NOMBRE", size = 0.6,  col = "black", fontfamily = "Roboto Condensed", 
        along.lines = T, remove.overlap = T, shadow = T, overwrite.lines = T, auto.placement = T)

I get this map:

rplot

The algorithms for these text functions (along lines, remove overlap, and auto placement) are not perfect, but with some tuning you may be able to get satisfying results.

@mtennekes mtennekes removed the bug label Feb 16, 2019
@hmeleiro
Copy link
Author

I get the same result using your code. I'll work with this functions to solve it out.

Thank you very much for your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants