Anjali Chandwani Anjali Chandwani - 3 months ago 20
R Question

R , Spatial Polygon

I am trying to create a spatial polygon data frame from a set of latitude,longitude and a corresponding value count with it. Each row need to be a single polygon. I can also create a shapefile and then again read it but instead I need to do it by simply creating a spatial polygon dataframe

Here is an example of my data:

head(Mydata)

NA. count... zipcode Latitude Longitude
1 1 1 0 44.200797 24.50230
2 3 67 560001 12.976594 77.59927
3 4 28 560002 12.963521 77.58211
4 5 90 560003 13.001914 77.57134
5 6 26 560004 12.943751 77.57376
6 7 34 560005 12.997989 77.62265


I have to depict the count corresponding to each location on an interactive map.
I have been through many other posts but could not find a solution. I am new to R so please bear with me.

Answer

Perhaps something like

library(dismo)
v <- voronoi(Mydata[, c("Longitude", "Latitude")]
Mydata$id <- 1:nrow(Mydata)

v <- merge(v, Mydata, by='id')
spplot(v, 'count')
Comments