Learn R Programming

oceanmap (version 0.1.7)

ggplotmaply: Converts a ggplot2 object from ggplotmap() to plotly

Description

This function converts a ggplot2 object created by oceanmap::ggplotmap() to a plotly object.

Usage

ggplotmaply(ggobj, fixedrange = F, grid = F, expand = 3)

Value

A plotly object.

Arguments

ggobj

Character string identifying regions predefined by the region_definitions-dataset, Raster* or Extent object (corresponds to v_area of the v-function). If missing, region is derived from geographical coordinates, denoted by lat and lon. See add.region to define new region definitions and delete.region to delete unproper region definitions.

fixedrange

Vector returning longitude coordinates of the area to be plotted.

grid

Whether a grid should be plotted (default is TRUE).

expand

By default, the underlying ggplotly-function does not stick to the plotting region of the ggobj, but extends it. This can result in missing countries or islands. The expand-argument extends the plotly-plotting window in each direction in order to cover the corresponding landmasks.

Author

Robert K. Bauer

Details

ggplotmaply uses the ggplotly function to convert the ggplot object into the plotly format.

See Also

ggplotmap, ggplotly

Examples

Run this code
library(ggplot2)

#### Example 1: plot landmask of the Western Mediterranean Sea
## a) by using longitude and latitude coordinates:
# lon <- c(-6, 16.5)
# lat <- c(34, 44.5)
# ggobj <- ggplotmap(xlim = lon, ylim = lat)
# ggobj
# ggplotmaply(ggobj, expand = 10)

## b) plot landmask with an extent-object:
# library(raster)
# ext <- extent(lon, lat)
# plotmap(ext, main = "Western Mediterranean Sea")
# ggobj <- ggplotmap(ext)
# ggplotmaply(ggobj)

## c) raster-object example:
# r <- raster(ext)
# ggobj <- ggplotmap(r)
# ggplotmaply(ggobj)

## d) Mediterranean Sea by keyword:
ggobj <- ggplotmap("med4") +
         geom_point(
           data = data.frame(x = 3.7008, y = 43.4079),
           aes(x, y),
           size = 5,
           colour = "blue"
         )
# ggplotmaply(ggobj, expand = 10)

## e) raster image plot with landmask:
# library(dplyr)
# data(cmap)
# setwd(system.file("test_files", package = "oceanmap"))
# nc <- nc2raster(ncfiles[1])
# rs2df <- nc[[1]] %>%
#          rasterToPoints() %>%
#          as.data.frame()
# names(rs2df) <- c("Lon","Lat","Conc")
# ggobj <- ggplot() + geom_raster(data = rs2df, aes(x = Lon, y = Lat, fill = Conc))
# ggobj_with_land_mask <- ggplotmap(add_to = ggobj) +
#                         scale_fill_gradientn(colours = cmap$jet)
# ggplotmaply(ggobj_with_land_mask)

Run the code above in your browser using DataLab