Hi @aho
I am checking what I did so we can discuss it in our next meeting.
The first limitation is that the plot cannot be displayed in a pop-up window if the s2dv legend is requested. That's why I allowed for more than one option in legend
parameter. legend
can be NULL, s2dv, or ggplot2 to allow checking the colors because the cut
function in geom_point
has a behavior that is not totally clear to me... The ggplot2 legend starts with open parenthesis "(" so it is supposed to include all lower values, but it doesn't do it. I included extra lines to modify the data (like https://earth.bsc.es/gitlab/es/s2dv/-/blob/develop-PlotRobinson/R/PlotRobinson.R#L68). It may be possible to solve it with include.lowest
parameter from cut()
.
The vertical
parameter from ColorBar
can be used now, but I don't find a way to better adjust the shape.
Well, talk to you soon.
Cheers,
Núria
source("R/PlotRobinson.R")
library(startR)
repos <- "/esarchive/exp/ecmwf/system5c3s/monthly_mean/$var$_f6h/$var$_$sdate$.nc"
data <- Start(dat = list(list(name = 'system5c3s', path = repos)),
var = 'tas',
sdate = '20170101',
ensemble = indices(1),
time = indices(1),
lon = 'all',
lat = 'all',
synonims = list(lat = c('lat', 'latitude'),
lon = c('lon', 'longitude')),
return_vars = list(time = 'sdate',
longitude = 'dat',
latitude = 'dat'),
metadata_dims = 'dat', # it can be omitted since it is automatically specified as 'dat'
retrieve = T)
lon <- attributes(data)$Variable$system5c3s$lon
lat <- attributes(data)$Variable$system5c3s$lat
data <- data - 273.15
mask <- drop(data)
mask[which(mask > -20 & mask < -10)] <- 0
mask[which(mask != 0)] <- 1
# Compare against PlotEquiMap:
library(RColorBrewer)
s2dv::PlotEquiMap(data, lon, lat, brks = seq(-40,50, 10),
cols = brewer.pal(9, 'PuOr'), filled.continents = F,
triangle_ends = c(FALSE, FALSE), colNA = 'green')
library(sf)
library(ggplot2)
library(rnaturalearth)
library(RColorBrewer)
library(cowplot) # to add s2dv legend
# legend NULL:
PlotRobinsonMap(data, lon, lat, brks = seq(-40, 40, 10),
cols = brewer.pal(9, 'PuOr')[-9], legend = NULL,
toptitle = paste("ECMWF SEAS5 / Air temperature at surface\nNot a metric/",
month.abb[1], "/ 2017"),
dots = mask,
caption = paste0("Nominal start date: 1st of January\n",
"Forecast month: 01\n", "Reference: ERA5"))
PlotRobinsonMap(data, lon, lat, brks = seq(-20, 20, 5),
cols = brewer.pal(9, 'PuOr')[-9], legend = 'ggplot2', size = 0.1,
toptitle = paste("ECMWF SEAS5 / Air temperature at surface\nNot a metric/",
month.abb[1], "/ 2017"),
dots = mask,
caption = paste0("Nominal start date: 1st of January\n",
"Forecast month: 01\n", "Reference: ERA5"),
fileout = "/esarchive/scratch/nperez/TestNewRobinson_s2dv.png", width = 8, height = 6,
triangle_ends = c(T, T), extra_margin = c(5, 0, 5, 0), col_inf = 'red', col_sup = 'blue')
PlotRobinsonMap(data, lon, lat, brks = seq(-20, 20, 5),
cols = brewer.pal(9, 'PuOr')[-9], legend = 's2dv', size = 0.1,
toptitle = paste("ECMWF SEAS5 / Air temperature at surface\nNot a metric/",
month.abb[1], "/ 2017"),
dots = mask,
caption = paste0("Nominal start date: 1st of January\n",
"Forecast month: 01\n", "Reference: ERA5"),
fileout = "/esarchive/scratch/nperez/TestNewRobinson_s2dv.png", width = 8, height = 6,
triangle_ends = c(T, T), extra_margin = c(5, 0, 5, 0), col_inf = 'red', col_sup = 'blue', vertical = TRUE)
PlotRobinsonMap(data, lon, lat, brks = seq(-20, 20, 5),
cols = brewer.pal(9, 'PuOr')[-9], legend = 's2dv', size = 0.1,
toptitle = paste("ECMWF SEAS5 / Air temperature at surface\nNot a metric/",
month.abb[1], "/ 2017"),
dots = mask,
caption = paste0("Nominal start date: 1st of January\n",
"Forecast month: 01\n", "Reference: ERA5"),
fileout = "/esarchive/scratch/nperez/TestNewRobinson_s2dv.png", width = 20, height = 20,
triangle_ends = c(T, T), extra_margin = c(5, 0, 5, 0), col_inf = 'red', col_sup = 'blue', vertical = FALSE)