0

I need to plot my variable Omega as a heat map on the Pacific Ocean. I have the coordinates and the Omega values but ggplot would only plot a world map while my omega appears as a separate figure (See image attached)

This is my data where y and x are Lat and Longs for my sites

    Country Omega     y       x               
1   Guam    3.28  144.7822 13.66660       
2   Guam    3.28  144.7605 13.62500        

This is the code I am using

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()

omega <- read.csv("map.csv", header = T)

head(omega)

g <- gg + 
    geom_polygon() + 
    geom_point(data = omega, aes(y = y, x = x, color = Omega)) + 
    theme_minimal()

map

I need to plot my Omega in my study sites and generate a heat map. Please any help would be very appreciated. Thank you very much

alistaire
  • 42,459
  • 4
  • 77
  • 117
Claire
  • 79
  • 1
  • 8
  • 2
    Looks like the x and y (long/lat) are backwards for the points. Is the location all you need to fix, or are you going for something more complicated, like a [choropleth](https://en.wikipedia.org/wiki/Choropleth_map) or a geographic [heat map](https://en.wikipedia.org/wiki/Heat_map)? – alistaire Apr 07 '18 at 02:29
  • I definitely need to fix the location and would like to create a heat map with my omega. Thanks so much – Claire Apr 07 '18 at 03:06
  • Fixing the location is easy; just change the aesthetics in `geom_point` to `aes(x = y, y = x, color = Omega)`. Making a heatmap is harder, although if you're just looking for density, [`geom_density_2d` or similar is packaged so as to make it pretty simple](https://stackoverflow.com/a/21803946/4497050). If you're smoothing something beyond density, [it can get more complicated](https://stats.stackexchange.com/a/306361/67615). – alistaire Apr 07 '18 at 03:33
  • Yay it worked! Thank you so much – Claire Apr 07 '18 at 04:11

1 Answers1

0

You might want to have a look at the leaflet package, it’s easier to use and better

library(leaflet)

df <- data.frame(Country=c("Guam","Guam"),
 Omega=c(3.28,3.28),
 y=c(144.7822, 144.7605),
 x=c(13.6660, 13.6250))

m <- leaflet(data=df)

content <- paste("Omega Value:",df$Omega)

m %>% addCircles(lng=~y, lat=~x, radius=df$Omega, popup=content) %>% 
     setView(lng=144.793732, lat=13.444304, zoom=10)

Your Map

Omega value as popup

ReKx
  • 996
  • 2
  • 10
  • 23