简体   繁体   English

连接标签文本和tmap图中的点的线

[英]line connecting label text and point in tmap plot

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. 我正在用形状文件做一个tmap情节,我想绘制几个点,我有长拉特坐标到形状文件上。 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. 这里是代码我必须显示上面的图:让我们假设上面的数据plot2_points.dfplot2_points.df ,而shapes是底层的形状文件。

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. tm_lines()不起作用,但我觉得这是为了完全不同的东西。 also, maybe it would work to do something with the just = option? 也许,使用just =选项可能会有用吗? 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 :) 非常感谢任何帮助,非常感谢:)

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). 虽然您要求的确切解决方案(从文本注释中绘制细线)是非常不切实际的,而且(据我所知)在tmap中实现,您可以通过使用tm_symbols()而不是tm_dots()并使用shape属性来改善底层问题对于spa名称( tm_dots()的形状设置为#16 =一个点)。 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. 这将是一种解决文本注释重叠问题的“lege artis”方式。

I agree that this would be a nice feature. 我同意这将是一个很好的功能。 One option is to set auto.placement = TRUE , which will rearrange the text labels to not overlap. 一个选项是设置auto.placement = TRUE ,这将重新排列文本标签不重叠。 It does not add connecting lines though. 但它不会添加连接线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM