View source: R/autoplot.bathy.R
autoplot.bathy | R Documentation |
Plots contour or image map from bathymetric data matrix of class bathy
with ggplot2
## S3 method for class 'bathy'
autoplot(x, geom="contour", mapping=NULL, coast=TRUE, ...)
x |
bathymetric data matrix of class |
geom |
geometry to use for the plot, i.e. type of plot; can be ‘contour’, ‘tile’ or ‘raster’. contour does a contour plot. tile and raster produce an image plot. tile allows true geographical projection through |
mapping |
additional mappings between the data obtained from calling |
coast |
boolean; wether to highlight the coast (isobath 0 m) as a black line |
... |
passed to the chosen geom(s) |
fortify.bathy
is called with argument x
to produce a data.frame compatible with ggplot2. Then layers are added to the plot based om the argument geom
. Finally, the whole plot is projected geographically using coord_map
(for geom="contour"
) or an approximation thereof.
Jean-Olivier Irisson
fortify.bathy
, plot.bathy
, read.bathy
, summary.bathy
# load NW Atlantic data and convert to class bathy
data(nw.atlantic)
atl <- as.bathy(nw.atlantic)
# basic plot
## Not run:
library("ggplot2")
autoplot.bathy(atl)
# plot images
autoplot.bathy(atl, geom=c("tile"))
autoplot.bathy(atl, geom=c("raster")) # faster but not resolution independant
# plot both!
autoplot.bathy(atl, geom=c("raster", "contour"))
# geom names can be abbreviated
autoplot.bathy(atl, geom=c("r", "c"))
# do not highlight the coastline
autoplot.bathy(atl, coast=FALSE)
# better colour scale
autoplot.bathy(atl, geom=c("r", "c")) +
scale_fill_gradient2(low="dodgerblue4", mid="gainsboro", high="darkgreen")
# set aesthetics
autoplot.bathy(atl, geom=c("r", "c"), colour="white", size=0.1)
# topographical colour scale, see ?scale_fill_etopo
autoplot.bathy(atl, geom=c("r", "c"), colour="white", size=0.1) + scale_fill_etopo()
# add sampling locations
data(metallo)
last_plot() + geom_point(aes(x=lon, y=lat), data=metallo, alpha=0.5)
# an alternative contour map making use of additional mappings
# see ?stat_contour in ggplot2 to understand the ..level.. argument
autoplot.bathy(atl, geom="contour", mapping=aes(colour=..level..))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.