vizi | R Documentation |
These functions provide a simple grammar of graphics approach to programming with R's base graphics system.
## Initialize a plot
vizi(data, ..., encoding = NULL, mark = NULL, params = NULL)
## Add plot components
add_mark(plot, mark, ..., encoding = NULL, data = NULL,
trans = NULL, params = NULL)
add_facets(plot, by = NULL, data = NULL,
nrow = NA, ncol = NA, labels = NULL,
drop = TRUE, free = "")
## Set plot attributes
set_title(plot, title)
set_channel(plot, channel, label = NULL,
limits = NULL, scheme = NULL, key = TRUE)
set_coord(plot, xlim = NULL, ylim = NULL, zlim = NULL,
rev = "", log = "", asp = NA, grid = TRUE)
set_engine(plot, engine = c("base", "plotly"))
set_par(plot, ..., style = NULL)
## Combine plots
as_layers(plotlist, ...)
as_facets(plotlist, ..., nrow = NA, ncol = NA,
labels = NULL, drop = TRUE, free = "")
data |
A |
... |
For |
encoding |
Encodings specified as a list rather than using .... |
mark |
The name of a supported mark, such as "points", "lines", etc. |
params |
Additional graphical parameters that are not mapped to the data, using either base R-style (e.g., pch, cex) or ggplot-style names (e.g., shape, size) |
plot , plotlist |
A |
title |
The title of the plot. |
channel |
The channel to modify, using ggplot-style names (e.g., shape, size). |
label , labels |
Plotting labels. |
limits |
The limits for the channel, specified as |
scheme |
A function or vector giving the scheme for encoding the channel. For example, a vector of colors, or a function that returns a vector of |
key |
Should a key be generated for the channel? |
xlim , ylim , zlim |
The plot limits. These only affect the plotting window, not the data. See |
rev |
A string specifying spatial dimensions that should be reversed. E.g., |
log , asp |
See |
grid |
Should a rectangular grid be included in the plot? |
engine |
The plotting engine. Default is to use base graphics. Using "plotly" requires the |
style |
The visual style to use for plotting. Currently supported styles are "light", "dark", and "classic". |
trans |
A list providing parameters for any transformations the mark supports. |
by |
A vector or formula giving the facet specification. |
nrow , ncol |
The number of rows and columns in the facet grid. |
drop |
Should empty facets be dropped? |
free |
A string specifying the free spatial dimensions during faceting. E.g., |
Currently supported marks include:
points
: Points (i.e., scatterplots).
lines
: Lines (i.e., line charts).
peaks
: Height (histogram) lines.
text
: Text labels.
rules
: Reference lines.
bars
: Bars for bar charts or histograms.
intervals
: Line intervals for representing error bars or confidence intervals.
boxplot
: Box-and-whisker plots.
image
: Raster graphics.
pixels
: 2D image from pixels.
voxels
: 3D image from voxels.
Currently supported encodings include:
x, y, z
: Positions.
xmin, xmax, ymin, ymax
: Position limits for intervals
and image
.
image
: Rasters for image
.
shape
: Shape of points (pch).
size
: Size of points (cex).
color, colour
: Color (col, fg).
fill
: Fill color (bg).
alpha
: Opacity.
linetype, linewidth, lineend, linejoin, linemetre
: Line properties (lty, lwd, lend, ljoin, lmitre).
An object of class vizi_plot
.
Kylie A. Bemis
vizi_points
,
vizi_lines
,
vizi_peaks
,
vizi_text
,
vizi_intervals
,
vizi_rules
,
vizi_bars
,
vizi_boxplot
,
vizi_image
,
vizi_pixels
,
vizi_voxels
require(datasets)
mtcars <- transform(mtcars,
am=factor(am, labels=c("auto", "manual")))
# faceted scatter plot
vizi(mtcars, x=~disp, y=~mpg) |>
add_mark("points") |>
add_facets(~mtcars$am)
# faceted scatter plot with color
vizi(mtcars, x=~disp, y=~mpg, color=~am) |>
add_mark("points",
params=list(shape=20, size=2, alpha=0.8)) |>
add_facets(~mtcars$am)
coords <- expand.grid(x=1:nrow(volcano), y=1:ncol(volcano))
# volcano image
vizi(coords, x=~x, y=~y, color=volcano) |>
add_mark("pixels") |>
set_coord(grid=FALSE) |>
set_par(xaxs="i", yaxs="i")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.