Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Why not use coord_proj("+proj=laea")? #12

Open
mdsumner opened this issue Oct 22, 2018 · 3 comments
Open

Why not use coord_proj("+proj=laea")? #12

mdsumner opened this issue Oct 22, 2018 · 3 comments

Comments

@mdsumner
Copy link
Collaborator

A rhetorical question, but should be interesting to explore different approaches.

How would you make this map?

image

The chlorophyll-a data:

u <- "https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/A20022132017243.L3m_MC_CHL_chl_ocx_9km.nc"
download.file(u, basename(u), mode = "wb")

The chlorophyll-a palette (breaks and colours):

pal <- palr::chlPal(palette = TRUE)

The projection and extents:

  • outer boundary is -20 (20S)
  • central longitude is 180, central latitude -90
  • inner graticule is xx <- c(0, 90, 180, 270, 360); yy <- c(-60, -40)
"+proj=laea +lat_0=-90 +lon_0=180 +datum=WGS84 +ellps=WGS84 +no_defs +towgs84=0, 0, 0"

The fronts are from orsifronts::orsifronts:

subset(orsifronts::orsifronts, front %in% c("pf", "saf"))
@mdsumner
Copy link
Collaborator Author

(having some problems saving this)

@mdsumner mdsumner changed the title Why not just coord_proj("+proj=laea")? Why not use coord_proj("+proj=laea")? Oct 22, 2018
@mdsumner
Copy link
Collaborator Author

for chl-a colours in gg, this almost works

# The breaks has a dummy 1000 in it, to capture any large values above the
# scaled maximum of 20 (it works for plotting rasters).

# In ggplot, you can use the gradientn to give it any sequence of colours, but
# you have to give it values scaled between 0,1. When I scaled pal$breaks that
# meant it spread out the range in the big gap between 20 and 1000, so I have to
# drop that. Here x is longitude, y is latitude, and "chl" is standard
# MODISA/SeaWiFS chlorophyll-a conc:
# 

## this is close
## chl a data frame of x, y, chl
names(chl) <- "chl"
chl[chl>20] <- 20
ggplot(as.data.frame(chl, xy = TRUE) %>% dplyr::filter(!is.na(chl)), aes(x, y)) + geom_raster(aes(fill = chl)) + scale_fill_gradientn(values = scales::rescale(head(pal$breaks, -1)), colours = pal$cols)

@mdsumner
Copy link
Collaborator Author

Primarily, to answer "why not ggdal::coord_proj"? This a raster, and coord_proj must assume long lat input, and there's no way to draw a projected grid like this, I believe the transformation happens after the geoms are set up (keen to be proved wrong!).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant