简体   繁体   English

尝试将 ggplot 用于 map 数据点到 shapefile

[英]Trying to use ggplot to map data points onto a shapefile

So I've had this problem for a few days now.所以我这几天一直有这个问题。 Basically what I have is a table with Field Site latitudes/longitudes represented as numerics.基本上我所拥有的是一个表格,其中字段站点纬度/经度表示为数字。 Associated with each Site Id is different chemical data that I want to plot.与每个站点 ID 相关联的是我想要 plot 的不同化学数据。 Here is what the table looks like.这是桌子的样子。 [Table Description][1][1]: https://i.stack.imgur.com/m4vH5.png [表格说明][1][1]: https://i.stack.imgur.com/m4vH5.png

I've also uploaded a shapefile.我还上传了一个 shapefile。 [Shapefile][2][2]: https://i.stack.imgur.com/sDFca.png [形状文件][2][2]: https://i.stack.imgur.com/sDFca.png

Now what I want to do is plot these data points with these chemical data unto the map using ggplot.现在我想做的是 plot 这些数据点与这些化学数据使用 ggplot 到 map。 I first used the code我第一次使用代码

    Master_cave_data <- Master_cave_data %>%
    st_as_sf(coords = c('Long_DD', 'Lat_DD'), crs = 4326, sf_column_name = NULL) 

This worked and I also converted the data set into a data frame using the code这行得通,我还使用代码将数据集转换为数据框

    Master_cave_data <- as.data.frame(Master_cave_data)

But I still can't plot the data points onto the shape file.但是我仍然不能将数据点 plot 到形状文件上。 Do I have to plot them using tmap?我是否必须使用 tmap 对它们进行 plot ? Thanks for the help谢谢您的帮助

You should be able to use geom_sf() in your ggplot call to plot sf objects .您应该能够在 ggplot 调用plot sf objects中使用geom_sf() You don't even need the as.data.frame conversion.您甚至不需要as.data.frame转换。

ggplot(Master_cave_data) +
geom_sf()  

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

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