连接标签文本和tmap图中的点的线 [英] line connecting label text and point in tmap plot

查看:148
本文介绍了连接标签文本和tmap图中的点的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用形状文件进行tmap绘制,我想在形状文件上绘制一些点,这些点具有长时坐标.我的绘图工作正常,但是地图上的点太多,这意味着不同点的标签文本是重叠的,并且通常来说不是特别清晰.

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.

这是一些示例数据:

       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

,这是我要显示上述情节的代码: 我们假设上面的数据框是plot2_points.df,而shapes是基础形状文件.

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)

我无法找到执行此操作的任何功能. tm_lines()不起作用,但是我觉得这是针对完全不同的东西.另外,也许可以使用just =选项执行某些操作?到目前为止,我尝试过的任何方法都没有任何效果,所以我想在这里问一下.任何帮助将不胜感激,非常感谢:)

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 :)

推荐答案

尽管您要求的确切解决方案(从文本注释中绘制细线)极其不切实际,并且(据我所知)在tmap中未实现,但您可以改善通过使用tm_symbols()而不是tm_dots()并为spa名称使用shape属性来解决潜在的问题(tm_dots()的形状设置为#16 =点).然后,将在标准图例中解释这些符号的含义.

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.

这篇关于连接标签文本和tmap图中的点的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆