| Title: | Interactive and High-Resolution Layered Graphics with Built-in World Maps |
|---|---|
| Description: | A layered grammar of graphics that compiles plots to a resolution-independent scene description and renders it through two back-ends: a self-contained SVG writer with embedded 'JavaScript' for interactive figures (tooltips, hover highlighting, zoom, pan and legend toggling) and R's own graphics devices for publication-quality output at any resolution. Geographic layers are first class: a simplified world polygon dataset ships with the package and can be drawn with several map projections, including Robinson, Equal Earth and an orthographic globe. The layered grammar follows Wickham (2010) <doi:10.1198/jcgs.2009.07098>; projections follow Snyder (1987) <doi:10.3133/pp1395> and, for Equal Earth, Savric, Patterson and Jenny (2019) <doi:10.1080/13658816.2018.1504949>; line simplification uses Douglas and Peucker (1973) <doi:10.3138/FM57-6770-U75U-7727>; the default colour scales follow the guidance on perceptually uniform palettes of Crameri, Shephard and Heron (2020) <doi:10.1038/s41467-020-19160-7>. |
| Authors: | Muhammad Farooqi [aut, cre] (ORCID: <https://orcid.org/0000-0003-4918-9791>) |
| Maintainer: | Muhammad Farooqi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-21 11:28:12 UTC |
| Source: | https://github.com/mqfarooqi1/orbis |
The + operator assembles a plot from parts, in the tradition of a layered
grammar of graphics.
## S3 method for class 'orb_spec' e1 + e2## S3 method for class 'orb_spec' e1 + e2
e1 |
An |
e2 |
A layer, scale, theme, labels or coordinate object to add. |
An orb_spec object.
orb(mtcars, x = wt, y = mpg) + orb_points() + orb_theme_dark()orb(mtcars, x = wt, y = mpg) + orb_points() + orb_theme_dark()
orb() creates a plot specification: it records the data and the mapping
from variables to visual channels. Layers, labels, scales and themes are
added with +. Nothing is drawn until the plot is printed or saved, so a
specification is cheap to build and modify.
orb(data, ...)orb(data, ...)
data |
A data frame. |
... |
Aesthetic mappings, given as |
Mappings are given as bare column names, in the style of a formula-free
grammar: orb(df, x = wt, y = mpg, colour = cyl). The recognised channels
are x, y, colour (or color), fill, size, label, group and
tooltip.
An object of class orb_spec.
orb_points(), orb_line(), orb_bars(), orb_area(),
orb_map(), orb_save(), orb_interactive()
p <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() pp <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() p
Fills the region between a line and a baseline.
orb_area( ..., data = NULL, fill = NULL, alpha = 0.45, baseline = 0, smooth = FALSE )orb_area( ..., data = NULL, fill = NULL, alpha = 0.45, baseline = 0, smooth = FALSE )
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
fill |
Fixed fill used when the |
alpha |
Opacity between 0 and 1. |
baseline |
Value the area is filled down to (default 0). |
smooth |
Draw a smoothed upper boundary. Default |
An object of class orb_layer.
df <- data.frame(t = 1:40, v = abs(cumsum(rnorm(40)))) orb(df, x = t, y = v) + orb_area(alpha = 0.5) + orb_line()df <- data.frame(t = 1:40, v = abs(cumsum(rnorm(40)))) orb(df, x = t, y = v) + orb_area(alpha = 0.5) + orb_line()
Draws one bar per observation. x may be discrete (a factor or character
column) or continuous. Bars start at zero.
orb_bars( ..., data = NULL, width = 0.72, fill = NULL, colour = NULL, alpha = 0.95, horizontal = FALSE )orb_bars( ..., data = NULL, width = 0.72, fill = NULL, colour = NULL, alpha = 0.95, horizontal = FALSE )
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
width |
Bar width as a fraction of the available slot (0-1). |
fill |
Fixed fill used when the |
colour |
Fixed colour used when the |
alpha |
Opacity between 0 and 1. |
horizontal |
Draw horizontal bars. Default |
An object of class orb_layer.
df <- data.frame(g = c("a", "b", "c"), v = c(3, 7, 5)) orb(df, x = g, y = v, fill = g) + orb_bars()df <- data.frame(g = c("a", "b", "c"), v = c(3, 7, 5)) orb(df, x = g, y = v, fill = g) + orb_bars()
The default coordinate system. Use it to return to Cartesian coordinates or to force a fixed aspect ratio.
orb_coord_cartesian(ratio = NULL)orb_coord_cartesian(ratio = NULL)
ratio |
Data units per y unit relative to x, or |
An object of class orb_coord.
orb(mtcars, x = wt, y = mpg) + orb_points() + orb_coord_cartesian()orb(mtcars, x = wt, y = mpg) + orb_points() + orb_coord_cartesian()
Sets the coordinate system to a geographic projection. Longitude and latitude are projected before being mapped to the panel, so map layers and point layers stay aligned.
orb_coord_map(projection = "equirectangular", centre = c(0, 0), max_lat = 84)orb_coord_map(projection = "equirectangular", centre = c(0, 0), max_lat = 84)
projection |
Projection name (see Details). |
centre |
Length-2 numeric vector, |
max_lat |
Latitude at which the Mercator projection is clipped. |
Available projections:
equirectangularLongitude and latitude used directly; simple and fast, but distorts area away from the equator.
mercatorConformal cylindrical projection; preserves angles,
greatly exaggerates high latitudes. Latitudes are clipped at
max_lat.
robinsonA compromise projection widely used for world maps.
mollweideEqual-area pseudo-cylindrical projection.
equalearthThe Equal Earth projection of Savric, Patterson and Jenny (2019): equal-area, like Mollweide, but with continents shaped much closer to the familiar Robinson outline. A good modern default for thematic world maps, because areas are not distorted.
orthographicA view of the globe from infinite distance, centred
on centre; the hemisphere facing away from the viewer is hidden.
An object of class orb_coord, to be added to a plot.
Snyder, J. P. (1987) "Map Projections: A Working Manual." US Geological Survey Professional Paper 1395. doi:10.3133/pp1395
Savric, B., Patterson, T. & Jenny, B. (2019) "The Equal Earth map projection." International Journal of Geographical Information Science 33, 454-465. doi:10.1080/13658816.2018.1504949
orb_worldmap() + orb_coord_map("robinson") orb_worldmap() + orb_coord_map("equalearth") orb_worldmap() + orb_coord_map("orthographic", centre = c(20, 15))orb_worldmap() + orb_coord_map("robinson") orb_worldmap() + orb_coord_map("equalearth") orb_worldmap() + orb_coord_map("orthographic", centre = c(20, 15))
Renders through R's grid graphics, so the plot appears on whatever device is
active. orb_save() is usually more convenient.
orb_draw(plot, width = 820, height = 520)orb_draw(plot, width = 820, height = 520)
plot |
An |
width, height
|
Logical size in pixels. |
NULL, invisibly. Called for its side effect.
p <- orb(mtcars, x = wt, y = mpg) + orb_points() f <- tempfile(fileext = ".png") grDevices::png(f, width = 820, height = 520) orb_draw(p) grDevices::dev.off() unlink(f)p <- orb(mtcars, x = wt, y = mpg) + orb_points() f <- tempfile(fileext = ".png") grDevices::png(f, width = 820, height = 520) orb_draw(p) grDevices::dev.off() unlink(f)
Faceting draws one panel per level of a grouping variable, laid out in a grid. Comparing many small panels that share a scale is often clearer than overplotting every group in one panel.
orb_facet(by, ncol = NULL, scales = c("fixed", "free_x", "free_y", "free"))orb_facet(by, ncol = NULL, scales = c("fixed", "free_x", "free_y", "free"))
by |
Bare column name to facet by, for example |
ncol |
Number of columns in the grid. The default chooses a roughly square arrangement. |
scales |
Whether panels share their axes: |
An object of class orb_facet, to be added to a plot.
orb(mtcars, x = wt, y = mpg) + orb_points() + orb_facet(cyl) orb(mtcars, x = wt, y = mpg) + orb_points() + orb_facet(cyl, ncol = 3, scales = "free")orb(mtcars, x = wt, y = mpg) + orb_points() + orb_facet(cyl) orb(mtcars, x = wt, y = mpg) + orb_points() + orb_facet(cyl, ncol = 3, scales = "free")
Places points on a map using the active projection. Use inside a plot that
also has an orb_map() layer, mapping x to longitude and y to latitude.
orb_geo_points( ..., data = NULL, size = 4, colour = "#F76707", alpha = 0.9, stroke = 0.8 )orb_geo_points( ..., data = NULL, size = 4, colour = "#F76707", alpha = 0.9, stroke = 0.8 )
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
size |
Point radius in pixels when |
colour |
Fixed colour used when the |
alpha |
Opacity between 0 and 1. |
stroke |
Outline width in pixels. |
An object of class orb_layer.
cities <- data.frame(long = c(2.35, -74, 151.2), lat = c(48.86, 40.7, -33.87), pop = c(11, 19, 5)) orb(cities, x = long, y = lat, size = pop) + orb_map() + orb_points(colour = "#F76707") + orb_coord_map("robinson")cities <- data.frame(long = c(2.35, -74, 151.2), lat = c(48.86, 40.7, -33.87), pop = c(11, 19, 5)) orb(cities, x = long, y = lat, size = pop) + orb_map() + orb_points(colour = "#F76707") + orb_coord_map("robinson")
Builds a self-contained HTML document containing the plot as inline SVG plus a small embedded script. The result works offline, needs no JavaScript library, and supports tooltips, hover highlighting, mouse-wheel zoom, dragging to pan, double-click to reset, and clicking legend keys to show or hide series.
orb_interactive( plot, file = NULL, width = 820, height = 520, title = "orbis plot" )orb_interactive( plot, file = NULL, width = 820, height = 520, title = "orbis plot" )
plot |
An |
file |
Optional output path. If |
width, height
|
Size in pixels. |
title |
Title of the HTML document. |
If file is given, the path (invisibly); otherwise an
htmltools tag object.
p <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() f <- tempfile(fileext = ".html") orb_interactive(p, file = f) file.exists(f) unlink(f)p <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() f <- tempfile(fileext = ".html") orb_interactive(p, file = f) file.exists(f) unlink(f)
Axis, legend and plot labels
orb_labs( title = NULL, subtitle = NULL, x = NULL, y = NULL, colour = NULL, fill = NULL, size = NULL, caption = NULL )orb_labs( title = NULL, subtitle = NULL, x = NULL, y = NULL, colour = NULL, fill = NULL, size = NULL, caption = NULL )
title |
Plot title. |
subtitle |
Plot subtitle. |
x, y
|
Axis titles. |
colour, fill, size
|
Legend titles for those channels. |
caption |
Caption shown under the plot. |
An object of class orb_labs, to be added to a plot.
orb(mtcars, x = wt, y = mpg) + orb_points() + orb_labs(title = "Fuel use", x = "Weight", y = "Miles per gallon")orb(mtcars, x = wt, y = mpg) + orb_points() + orb_labs(title = "Fuel use", x = "Weight", y = "Miles per gallon")
Connects observations in the order they appear, optionally split by a
group or colour mapping.
orb_line( ..., data = NULL, width = 1.8, colour = NULL, alpha = 1, smooth = FALSE )orb_line( ..., data = NULL, width = 1.8, colour = NULL, alpha = 1, smooth = FALSE )
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
width |
Line width in pixels. |
colour |
Fixed colour used when the |
alpha |
Opacity between 0 and 1. |
smooth |
Draw a smoothed curve through the points instead of straight
segments (a Catmull-Rom style spline). Default |
An object of class orb_layer.
df <- data.frame(t = 1:50, v = cumsum(rnorm(50))) orb(df, x = t, y = v) + orb_line(width = 2, smooth = TRUE)df <- data.frame(t = 1:50, v = cumsum(rnorm(50))) orb(df, x = t, y = v) + orb_line(width = 2, smooth = TRUE)
Draws country polygons from the built-in world_map dataset, or from a data
frame of your own with long, lat and group columns. The projection is
set with orb_coord_map(); if none is given, an equirectangular projection
is used.
orb_map( data = NULL, values = NULL, region_col = "region", value_col = NULL, fill = "#DEE2E6", colour = "#FFFFFF", width = 0.4, alpha = 1, palette = "viridis", na_fill = "#E9ECEF", ocean = NULL )orb_map( data = NULL, values = NULL, region_col = "region", value_col = NULL, fill = "#DEE2E6", colour = "#FFFFFF", width = 0.4, alpha = 1, palette = "viridis", na_fill = "#E9ECEF", ocean = NULL )
data |
Optional polygon data frame with columns |
values |
Optional data frame giving one value per region, used to fill the polygons. |
region_col, value_col
|
Column names in |
fill |
Fixed fill colour used when |
colour |
Border colour. |
width |
Border width in pixels. |
alpha |
Opacity between 0 and 1. |
palette |
Continuous palette used for the choropleth; see
|
na_fill |
Fill colour for regions with no value. |
ocean |
Optional colour for the sea drawn behind the land: a disc for the orthographic globe, the panel background otherwise. |
To build a choropleth, supply values: a data frame with a region column
and a value column, matched to map regions by name.
An object of class orb_layer.
orb_worldmap() vals <- data.frame(region = c("Brazil", "India", "France"), v = c(3, 9, 5)) orb(world_map) + orb_map(values = vals, region_col = "region", value_col = "v") + orb_coord_map("robinson")orb_worldmap() vals <- data.frame(region = c("Brazil", "India", "France"), v = c(3, 9, 5)) orb(world_map) + orb_map(values = vals, region_col = "region", value_col = "v") + orb_coord_map("robinson")
Plot-level options
orb_options(legend = NULL, grid = NULL, interactive = NULL)orb_options(legend = NULL, grid = NULL, interactive = NULL)
legend |
Should a legend be drawn when a colour, fill or size mapping
is present? Default |
grid |
One of |
interactive |
Should the SVG output embed interactive behaviour
(tooltips, hover highlighting, zoom, pan and legend toggling)? Default
|
An object of class orb_opts, to be added to a plot.
orb(mtcars, x = wt, y = mpg) + orb_points() + orb_options(grid = "y")orb(mtcars, x = wt, y = mpg) + orb_points() + orb_options(grid = "y")
Lists the palette names accepted by orb_scale_colour() and
orb_scale_fill().
orb_palettes()orb_palettes()
A list with two character vectors: continuous (sequential and
diverging ramps) and discrete (qualitative palettes).
orb_palettes()orb_palettes()
Draws one mark per observation: a scatter plot, or a bubble chart when a
size mapping is present.
orb_points( ..., data = NULL, size = 3.2, colour = NULL, fill = NULL, alpha = 0.9, stroke = 0.8 )orb_points( ..., data = NULL, size = 3.2, colour = NULL, fill = NULL, alpha = 0.9, stroke = 0.8 )
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
size |
Point radius in pixels when |
colour |
Fixed colour used when the |
fill |
Fixed fill used when the |
alpha |
Opacity between 0 and 1. |
stroke |
Outline width in pixels. |
An object of class orb_layer.
orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points(alpha = 0.85)orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points(alpha = 0.85)
Writes a plot to disk. The format is taken from the file extension:
orb_save(plot, file, width = 820, height = 520, dpi = 300, interactive = TRUE)orb_save(plot, file, width = 820, height = 520, dpi = 300, interactive = TRUE)
plot |
An |
file |
Output path. The extension selects the format. |
width, height
|
Logical size in pixels (the drawing is laid out at this
size, then rendered at |
dpi |
Resolution for raster formats. 96 is screen resolution; 300 is a common print requirement; 600 gives very high resolution output. |
interactive |
For |
.svgVector output from the built-in SVG writer. Being a vector format it is resolution independent - it stays sharp at any size.
.htmlA self-contained interactive page (see orb_interactive()).
.pdfVector output through R's PDF device.
.png, .tiff, .jpeg
Raster output at the requested dpi; use
300 or more for print.
The file path, invisibly.
orb_svg(), orb_interactive(), orb_draw()
p <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() f <- tempfile(fileext = ".png") orb_save(p, f, dpi = 300) file.exists(f) unlink(f)p <- orb(mtcars, x = wt, y = mpg, colour = cyl) + orb_points() f <- tempfile(fileext = ".png") orb_save(p, f, dpi = 300) file.exists(f) unlink(f)
Scales control how data values are converted to visual values: which colours a variable spans, how large points become, and the limits and transformation of the axes.
orb_scale_colour(palette = "viridis", limits = NULL, reverse = FALSE) orb_scale_fill(palette = "viridis", limits = NULL, reverse = FALSE) orb_scale_size(range = c(2, 14), limits = NULL) orb_scale_x(limits = NULL, trans = "identity", breaks = NULL, expand = 0.04) orb_scale_y(limits = NULL, trans = "identity", breaks = NULL, expand = 0.04)orb_scale_colour(palette = "viridis", limits = NULL, reverse = FALSE) orb_scale_fill(palette = "viridis", limits = NULL, reverse = FALSE) orb_scale_size(range = c(2, 14), limits = NULL) orb_scale_x(limits = NULL, trans = "identity", breaks = NULL, expand = 0.04) orb_scale_y(limits = NULL, trans = "identity", breaks = NULL, expand = 0.04)
palette |
Palette name (see |
limits |
Numeric length-2 vector giving the data range to map, or
|
reverse |
Reverse the direction of the palette. |
range |
Length-2 numeric vector giving the smallest and largest radius
in pixels, for |
trans |
Axis transformation: |
breaks |
Numeric vector of axis breaks, or |
expand |
Fraction of the data range added as padding at each end. |
An object of class orb_scale, to be added to a plot.
p <- orb(mtcars, x = wt, y = mpg, colour = hp) + orb_points() p + orb_scale_colour("magma", reverse = TRUE) p + orb_scale_y(limits = c(10, 35))p <- orb(mtcars, x = wt, y = mpg, colour = hp) + orb_points() p + orb_scale_colour("magma", reverse = TRUE) p + orb_scale_y(limits = c(10, 35))
Produces a standalone SVG image of a plot. SVG is a vector format, so the result is resolution independent: it stays sharp at any size or zoom level, which is what makes it suitable both for the web and for print.
orb_svg(plot, width = 820, height = 520, interactive = TRUE, id = NULL)orb_svg(plot, width = 820, height = 520, interactive = TRUE, id = NULL)
plot |
An |
width, height
|
Size in pixels. |
interactive |
Embed JavaScript for tooltips, hover highlighting, zoom,
pan and legend toggling. Set |
id |
Element id used by the embedded script; generated if |
A character string containing SVG (and, if requested, a wrapping
div with the script).
p <- orb(mtcars, x = wt, y = mpg) + orb_points() s <- orb_svg(p, interactive = FALSE) substr(s, 1, 40)p <- orb(mtcars, x = wt, y = mpg) + orb_points() s <- orb_svg(p, interactive = FALSE) substr(s, 1, 40)
Draws a text label at each observation.
orb_text(..., data = NULL, size = 10, colour = NULL, dy = 0, alpha = 1)orb_text(..., data = NULL, size = 10, colour = NULL, dy = 0, alpha = 1)
... |
Aesthetic mappings for this layer only, as |
data |
Optional data frame overriding the plot data. |
size |
Font size in points. |
colour |
Fixed colour used when the |
dy |
Vertical offset in pixels (negative moves up). |
alpha |
Opacity between 0 and 1. |
An object of class orb_layer.
df <- data.frame(x = 1:3, y = c(2, 4, 3), n = c("a", "b", "c")) orb(df, x = x, y = y, label = n) + orb_points() + orb_text(dy = -10)df <- data.frame(x = 1:3, y = c(2, 4, 3), n = c("a", "b", "c")) orb(df, x = x, y = y, label = n) + orb_points() + orb_text(dy = -10)
Themes control the non-data appearance of a plot: colours of the background,
grid, axes and text, plus base font size. Add a theme to a plot with +.
orb_theme_light(base_size = 12, ...) orb_theme_dark(base_size = 12, ...) orb_theme_minimal(base_size = 12, ...) orb_theme_ink(base_size = 12, ...)orb_theme_light(base_size = 12, ...) orb_theme_dark(base_size = 12, ...) orb_theme_minimal(base_size = 12, ...) orb_theme_ink(base_size = 12, ...)
base_size |
Base font size in points (default 12). |
... |
Named theme elements to override, for example
|
An object of class orb_theme, to be added to a plot.
p <- orb(mtcars, x = wt, y = mpg) + orb_points() p + orb_theme_dark() p + orb_theme_light(base_size = 14)p <- orb(mtcars, x = wt, y = mpg) + orb_points() p + orb_theme_dark() p + orb_theme_light(base_size = 14)
A convenience wrapper that returns a complete world map plot, optionally shaded by a value per region.
orb_worldmap( values = NULL, region_col = "region", value_col = NULL, projection = "equirectangular", palette = "viridis", ocean = NULL, title = NULL )orb_worldmap( values = NULL, region_col = "region", value_col = NULL, projection = "equirectangular", palette = "viridis", ocean = NULL, title = NULL )
values, region_col, value_col
|
Passed to |
projection |
Projection name; see |
palette |
Continuous palette name; see |
ocean |
Optional sea colour; see |
title |
Optional plot title. |
An orb_spec object.
orb_worldmap(projection = "orthographic")orb_worldmap(projection = "orthographic")
A simplified set of world country outlines, suitable for thematic world maps at typical figure sizes. Polygon rings were simplified with the Douglas-Peucker algorithm to keep the dataset small while preserving the recognisable shape of coastlines and borders.
world_mapworld_map
A data frame with four columns:
Longitude in degrees, from -180 to 180.
Latitude in degrees, from -90 to 90.
Integer identifying the polygon ring a point belongs to. Points must be drawn ring by ring; a country made of several land masses has several rings.
Country or territory name.
Coordinates are unprojected longitude and latitude in degrees; use
orb_coord_map() to choose a projection.
Derived from the world database of the maps package, whose boundaries come from Natural Earth (https://www.naturalearthdata.com), released into the public domain.
Douglas, D. H. & Peucker, T. K. (1973) "Algorithms for the reduction of the number of points required to represent a digitized line or its caricature." Cartographica 10, 112-122. doi:10.3138/FM57-6770-U75U-7727
str(world_map) length(unique(world_map$region)) orb_worldmap()str(world_map) length(unique(world_map$region)) orb_worldmap()