-1

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.

Cyrus Mohammadian
  • 4,982
  • 6
  • 33
  • 62
  • 1
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Jul 07 '16 at 09:42
  • I am sorry but this is my first ques on stack overflow . I'll keep it in mind and edit my question to make it more clear. – Anjali Chandwani Jul 07 '16 at 09:50
  • What is count? You have for each point a vount value. I thought you want polygon data frame. Are you sure that you do not want a point data frame? – Alex Jul 07 '16 at 17:09
  • I actually need to create an interactive choropleth or heat map in which when we hover over an area, count should be displayed. I got a solution which can create it using a spatial polygon data frame. In that it is reading a shape file and using leaflet for plotting. I cannot download a shapefile as I need to create a portal where user can enter different data and according to that automatically spatial polygon data frame is created and map is plotted. – Anjali Chandwani Jul 08 '16 at 05:05
  • Can you provide your data? – Alex Jul 08 '16 at 12:06
  • No I am sorry. I can't, but it is similar to the example given above. – Anjali Chandwani Jul 11 '16 at 10:11

1 Answers1

0

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')
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • I need to create an interactive choropleth map which has a base of a location defined by zipcode in the data like the one at: http://openbangalore.org/maps/ but areas differentiated using colors based on their count. – Anjali Chandwani Jul 08 '16 at 09:36
  • This is of course not possible based on your data alone (and a different question). But it is simple to do to that: get a datasource with the zip boundaries and then do `z <- merge(zip, Mydata, by='zipcode)` – Robert Hijmans Jul 08 '16 at 15:30