Skip to main content
added 196 characters in body
Source Link

I am trying to color in specific grid cells within a map to highlight sampling effort.

I can generate the map but then I am unsure how to use utilize the data points I have to color in the entire grid cell.

(The data points I have are for the top left hand corner of a grid cell)

I have tried using stat_density2d (i.e. a heatmap) but cannot get it working.

library(ggOceanMaps)
library(ggOceanMapsData)

dt <- data.frame(lon = c(35, 35, 60, 60), lat = c(-25, -25, -40, -40))

grid_2_colour <- data.frame(lat=c(-29), long=c(50))

basemap(data = dt, bathymetry = TRUE,
        lon.interval = 1,
        lat.interval = 1,
       # bathy.style = "contour_blues",
        bathy.border.col = NA,
        bathy.size = 0.1,
        bathy.alpha = 1)  +
 stat_density2d(data = grid_2_colour, aes(x = long, y = lat, fill =..density..), geom = 'tile', contour = F) 

I am trying to color in specific grid cells within a map to highlight sampling effort.

I can generate the map but then I am unsure how to use utilize the data points I have to color in the entire grid cell.

(The data points I have are for the top left hand corner of a grid cell)

library(ggOceanMaps)
library(ggOceanMapsData)

dt <- data.frame(lon = c(35, 35, 60, 60), lat = c(-25, -25, -40, -40))

grid_2_colour <- data.frame(lat=c(-29), long=c(50))

basemap(data = dt, bathymetry = TRUE,
        lon.interval = 1,
        lat.interval = 1,
       # bathy.style = "contour_blues",
        bathy.border.col = NA,
        bathy.size = 0.1,
        bathy.alpha = 1) 

I am trying to color in specific grid cells within a map to highlight sampling effort.

I can generate the map but then I am unsure how to use utilize the data points I have to color in the entire grid cell.

(The data points I have are for the top left hand corner of a grid cell)

I have tried using stat_density2d (i.e. a heatmap) but cannot get it working.

library(ggOceanMaps)
library(ggOceanMapsData)

dt <- data.frame(lon = c(35, 35, 60, 60), lat = c(-25, -25, -40, -40))

grid_2_colour <- data.frame(lat=c(-29), long=c(50))

basemap(data = dt, bathymetry = TRUE,
        lon.interval = 1,
        lat.interval = 1,
       # bathy.style = "contour_blues",
        bathy.border.col = NA,
        bathy.size = 0.1,
        bathy.alpha = 1)  +
 stat_density2d(data = grid_2_colour, aes(x = long, y = lat, fill =..density..), geom = 'tile', contour = F) 

edited tags
Link
Source Link

Overlay colors onto specific 1 degree x 1 degree grid squares in R

I am trying to color in specific grid cells within a map to highlight sampling effort.

I can generate the map but then I am unsure how to use utilize the data points I have to color in the entire grid cell.

(The data points I have are for the top left hand corner of a grid cell)

library(ggOceanMaps)
library(ggOceanMapsData)

dt <- data.frame(lon = c(35, 35, 60, 60), lat = c(-25, -25, -40, -40))

grid_2_colour <- data.frame(lat=c(-29), long=c(50))

basemap(data = dt, bathymetry = TRUE,
        lon.interval = 1,
        lat.interval = 1,
       # bathy.style = "contour_blues",
        bathy.border.col = NA,
        bathy.size = 0.1,
        bathy.alpha = 1)