0

I have data for 357 grids for India. with some value at every grid. I want to plot it in R. I use following lines

library(maps)
library(ggplot2)
data <- read.csv("foo.csv")
ind <- map(database = "world", regions = "india", exact = FALSE, boundary = T)
india <- map_data(ind , region = "india", exact = F)
(ggplot(aes(x=x, y=y, fill=z), data=data) + geom_tile()) + geom_polygon(data=india, aes(x=long, y=lat, group=group), colour="black", fill="red", alpha=0)

But I got a very bad map. How can I improve this image? I have seen some good ways at R Plot Filled Longitude-Latitude Grid Cells on Map But unfortunately these methods did not work in my case. Any will be highly appreciated.

Community
  • 1
  • 1
Pankaj
  • 1,296
  • 2
  • 13
  • 23
  • 1
    Why did you use geom_tile? – lawyeR Jun 04 '15 at 19:49
  • Dear LawyeR, without `geom_tile()` I will get only half boundary of India. I am not able to get the fill plot of my data without this. – Pankaj Jun 04 '15 at 22:07
  • Dear lawyeR, any help in this direction would be appreciated. I am still stuck here. – Pankaj Jun 16 '15 at 19:17
  • Can you provide at least some of your data, perhaps using dput()? Or make your question reproducible for people who take time to answer. I am interested but I can't offer much without being able to run your code with some data. – lawyeR Jun 16 '15 at 19:54
  • Dear lawyer, [here](https://drive.google.com/file/d/0B7TdGA0qFbykUENhRlM3Tkd5ZTQ/view?usp=sharing) you can find the data set. – Pankaj Jun 16 '15 at 20:45

1 Answers1

0

You need to have an Indian state associated with your observations. With that, I believe you can merge your map data and your Indian-state observation data. Here is example code.

states_map <- map_data("state")
fee_map <- merge(states_map, spendstate, by.x = "region", by.y = "state")
fee_map <- arrange(fee_map, group, order) # eeed to sort polygons in right order

Then, using my code, something like:

ggplot(fee_map, aes(x = long, y = lat,  group = group, fill = obs)) + 
  geom_polygon() + 
  coord_map("polyconic") + reestheme + labs(x = "", y = "") +
  scale_fill_gradient(low = "green", high = "red") +
  theme(legend.position = "bottom") + 
  theme( legend.position=c(0,0),  legend.justification=c(0, 0)) + # lower left and lower left just
  theme(legend.text = element_text(colour= "black", size=10, hjust=0,vjust=0,face="plain")) + 
  theme(axis.text = element_blank()) + theme(axis.ticks = element_blank())
lawyeR
  • 7,488
  • 5
  • 33
  • 63
  • Dear lawyeR, Thanks for reply. My data in this question is grid data. There is no state included in this. According to your previous suggestion, I have provided a link above as sample data set. – Pankaj Jun 18 '15 at 06:28