line connecting label text and point in tmap plot

大兔子大兔子 提交于 2019-12-10 23:05:35

问题


i'm doing a tmap plot with a shape file, and i want to be plotting several points for which i have long-lat coordinates onto the shape file. i've got the plot working just fine, however there are too many points on the map, meaning that the label text for different points is overlapping, and is just not particularly legible in general.

here's what the plot currently looks like. i would really like for the text in the plot to be outside of the actual map, and to be connected to the points in the plot by thin lines which blend into the overall aesthetic of the map.

here's some example data:

       name      long      lat
1  location -71.40909 41.82426
2  location -71.41959 41.82796
3  location -71.41277 41.79667
4  location -71.37327 41.81737
5  location -71.37170 41.89266
6  location -71.33356 41.87736

and here's the code i've got to display the above plot: let's assume the above dataframe is plot2_points.df, while shapes is the underlying shape file.

library(tmap)
library(sp)
library(rgdal)


coordinates(plot2_points.df) <- c("long", "lat")
proj4string(plot2_points.df) <- CRS("+proj=longlat +datum=WGS84")

plot2_points.df <- spTransform(plot2_points.df, CRS("+proj=utm +zone=19T ellps=WGS84"))

# plot
tm_shape(shapes) + tm_borders() + tm_shape(plot2_points.df) + tm_dots(col = "blue", size = 0.4) + tm_text("name", col = "blue", size = 0.75, just = "top", ymod = 0.75)

i have not been able to find any function that comes anywhere near doing this. tm_lines() doesn't work, but i feel like this is intended for something completely different. also, maybe it would work to do something with the just = option? so far nothing i've tried had any kind of effect, so i figured i'd ask here. any help would be greatly appreciated, thank you very much :)


回答1:


While the exact solution you are asking for (drawing thin lines from text annotations) is extremely impractical and not (to my knowledge) implemented in tmap you could improve the underlying problem by using tm_symbols() instead of tm_dots() and using the shape property for the spa name (tm_dots() have the shape set to #16 = a dot). The meaning of the symbols would be then explained in a standard legend.

This would be a more "lege artis" way of solving the problem of overlapping text annotations.



来源:https://stackoverflow.com/questions/48859637/line-connecting-label-text-and-point-in-tmap-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!