4

I am trying to plot all my sites on a ggplot map. I have 5 locations with multiple sites per location, but when I try to plot all my sites, it only displays one point per location instead of one point per site. I have 34 sites and 5 locations so I need a map with 34 points instead of 5! Any help would be super appreciated! Thanks so so much

These are the data with y and x as my long and lat.

Location PAR y x Guam GFA 201.09952 144.8786111 13.495 Guam GFA2 179.04171 144.6597222 13.41638889 Guam GFA3 67.66379 144.2761111 13.47333333 Guam GFB1 201.09952 144.7105556 13.31416667 Guam GFB2 179.04171 144.655 13.50194444 Guam GFB3 67.66379 144.8697222 13.37472222

I need to plot all my 6 sites for Guam. This is the code I am using and the final output

map.world <- map_data(map="world")
gg <- ggplot()
gg <- gg + theme(legend.position="none")
gg <- gg + geom_map(data=map.world, map=map.world, aes(map_id=region, x=long, y=lat), fill="white", colour="black", size=0.25) + theme_bw()
gg

par<-read.csv("parmap.csv", header=T)
head(par)
g<-gg+ geom_polygon() + 
  geom_point(data=par, aes(x = y, y = x, color=PAR)) +theme_minimal()
g

MAP

Sathish
  • 12,453
  • 3
  • 41
  • 59
Claire
  • 79
  • 1
  • 8

1 Answers1

0

You may need to zoom your map near point of interest i.e. 'Guam' in this case.

One approach could be like below

library(ggplot2)
library(ggmap)

#get the map
center = paste(min(df$lat)+(max(df$lat)-min(df$lat))/2, 
               min(df$lon)+(max(df$lon)-min(df$lon))/2, sep=" ")
map <- get_map(location = center, maptype = "roadmap", zoom = 8, source = "google", color="bw")
p <- ggmap(map)

#plot points on the map
plt <- p +
  geom_point(data=df, aes(x = lon, y = lat, color = PAR)) +
  scale_color_gradientn(colours = rainbow(10)) +
  theme_minimal()
plt

Update: I have slightly modified your sample data. You can notice that I have added one more location in sample data to plot all 7 points (i.e. 6 sites for one location and 1 site for another location) on the map.

Output plot is: enter image description here

Note: In case you get geocode failed with status OVER_QUERY_LIMIT error then this link might be helpful.

Sample data:

df <- structure(list(Location = c("Guam", "Guam", "Guam", "Guam", "Guam", 
"Guam", "N_Mariana_Islands"), sites = c("GFA", "GFA2", "GFA3", 
"GFB1", "GFB2", "GFB3", "NMI1"), PAR = c(201.09952, 179.04171, 
67.66379, 201.09952, 179.04171, 67.66379, 100), lon = c(144.8786111, 
144.6597222, 144.2761111, 144.7105556, 144.655, 144.8697222, 
145.192522), lat = c(13.495, 13.41638889, 13.47333333, 13.31416667, 
13.50194444, 13.37472222, 14.150817)), .Names = c("Location", 
"sites", "PAR", "lon", "lat"), class = "data.frame", row.names = c(NA, 
-7L))
#           Location sites       PAR      lon      lat
#1              Guam   GFA 201.09952 144.8786 13.49500
#2              Guam  GFA2 179.04171 144.6597 13.41639
#3              Guam  GFA3  67.66379 144.2761 13.47333
#4              Guam  GFB1 201.09952 144.7106 13.31417
#5              Guam  GFB2 179.04171 144.6550 13.50194
#6              Guam  GFB3  67.66379 144.8697 13.37472
#7 N_Mariana_Islands  NMI1 100.00000 145.1925 14.15082
Prem
  • 11,775
  • 1
  • 19
  • 33
  • Thank you so much @Prem! GF are actually my sites! so it keeps coloring the points by sites and not by PAR... and it would not let me plot the sites from other locations..sorry I am very new to this – Claire Apr 29 '18 at 18:20
  • how could I eventually zoom in the map I created to show all my points? Thank you – Claire Apr 29 '18 at 19:02