根据频率绘制带有符号的地理地图
我想根据一个县内疾病的发生频率绘制一张有 n 个正方形的地理地图。就像这里的这个:
但我不知道如何使用 R 或 qGIS 来做到这一点。 谢谢大家的帮助。
I would like to plot a geographical map with n numbers of squares according to the frequency of a disease within a county. Like this one here:
But I couldn't figure out how to do this with R or qGIS.
Thanks for y'all help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先编写一个名为“stackbox”的小函数,该函数在正确的位置绘制(使用“rect”)堆栈的方块。
这是该函数的第一行:
然后为每个有病例的县调用该函数。
在这个过程中你到底被困在哪里了?
下面是完整的函数:
示例:
要在地图上执行此操作,您需要 sp 和 maptools 包,以及包含您的数据的 shapefile 或其他地理空间数据源:
我选择的颜色看起来有点像您原来的颜色。请注意,这些框位于绘图坐标中,因此我必须将它们设置为 0.1 度。您可能希望将您的地图转换为欧几里德投影(使用包:gdal 中的 spTransform),然后它们将采用这些单位并正确正方形。
不过,像原来那样做漂亮的文本标签会很棘手......
First write a little function called 'stackbox' that plots (using "rect") the squares for the stack in the right place.
Here's the first line of that function:
Then call that function for every county that has cases.
Where exactly were you stuck in the process?
Here's the function in full:
Example:
To do this on a map, you need the sp and maptools packages, and a shapefile or other geospatial data source that has your data in it:
I've picked colours that look a bit like your original. Note that the boxes are in plot coordinates, so I had to make them 0.1 of a degree. You may wish to transform your map to a euclidean projection (using spTransform from package:gdal) and then they'll be in those units and properly square.
Doing nice text labels like in your original would be tricky though...
作为替代方案,我建议使用气泡图,使用点几何图形使用 ggplot2 很容易制作气泡图。帮助页面的示例 (http://had.co.nz/ggplot2/geom_point.html< /a>):
导致:
气泡的大小代表测量的量。该示例没有使用地理坐标,但可以很容易地使用它们。 ggplot2 包还支持添加空间多边形作为附加层,例如使用 geom_path。 coord_map 的帮助文件显示了一些使用地图数据的示例。另请参阅将 SpatialPolygons 对象转换为 data.frame 的 fortify 函数(ggplot2 需要该函数)。
As an alternative I would suggest a bubble plot, which is quite easy to make using ggplot2 using the point geometry. An example form the help pages (http://had.co.nz/ggplot2/geom_point.html):
which leads to:
The size of the bubble represents the amount measured. The example does not use geographical coordinates, but they can be used easily. The ggplot2 package also supports adding spatial polygons as an additional layer, e.g. using geom_path. The help file of coord_map shows a few examples using map data. See also the fortify function to transform a SpatialPolygons object to a data.frame (which is needed for ggplot2).