| Title: | Grammar of Graphics for 'base' Plot |
| Version: | 0.1.0 |
| Description: | Proof of concept for implementing grammar of graphics using base plot. The bbplot() function initializes a 'bbplot' object to store input data, aesthetic mapping, a list of layers and theme elements. The object will be rendered as a graphic using base plot command if it is printed. |
| Imports: | graphics, magrittr, rlang, scales, methods, utils |
| Suggests: | stats, ape, aplot (≥ 0.0.8), dplyr, ggplotify (≥ 0.1.0), quarto |
| VignetteBuilder: | quarto |
| ByteCompile: | true |
| License: | Artistic-2.0 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-01-15 16:01:54 UTC; HUAWEI |
| Author: | Guangchuang Yu |
| Maintainer: | Guangchuang Yu <guangchuangyu@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-01-15 16:50:02 UTC |
as.bbplot
Description
convert a base plot function to a bbplot object
Usage
as.bbplot(fun)
Arguments
fun |
a function that plot something in base graphics |
Details
the base plot function will be plotted as a canvas and users can apply theme and add layers to it
Value
A bbplot object
Author(s)
Guangchuang Yu
bb_aes
Description
aesthetic mapping
Usage
bb_aes(x, y, ...)
Arguments
x |
x variable |
y |
y variable |
... |
other mappings |
Details
aesthetic mapping for bbplot
Value
enquo expression describing variables mapping to aesthetic attributes
Author(s)
Guangchuang Yu
layer
Description
layer
Usage
bb_bar(mapping = NULL, data = NULL, stat = "identity", width = 0.9, ...)
bb_errorbar(mapping = NULL, data = NULL, orientation = "y", width = 0.5, ...)
bb_line(mapping = NULL, data = NULL, ...)
bb_lm(mapping = NULL, data = NULL, ...)
bb_point(mapping = NULL, data = NULL, position = "identity", ...)
bb_segment(mapping = NULL, data = NULL, ...)
bb_text(mapping = NULL, data = NULL, ...)
bb_tile(mapping = NULL, data = NULL, ...)
Arguments
mapping |
aesthetic mapping |
data |
layer data |
stat |
one of 'identity' or 'count' |
width |
bar width or errorbar cap width |
... |
addition parameter for the layer |
orientation |
one of 'y' or 'x' |
position |
one of 'identity' or 'jitter' |
Details
bbplot layers
Value
A modified bbplot object
Author(s)
Guangchuang Yu
Examples
library(plotbb)
p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) +
bb_point() + bb_lm(bb_aes(group=cyl), lwd=2)
bb_facet_wrap
Description
Facet a bbplot object into multiple panels.
Usage
bb_facet_wrap(facets, ncol = NULL, nrow = NULL, scales = "fixed")
Arguments
facets |
a formula specifying faceting variable, e.g. |
ncol |
number of columns. |
nrow |
number of rows. |
scales |
scale behavior across facets, one of 'fixed', 'free', 'free_x', or 'free_y'. |
Value
A modified bbplot object
Author(s)
Guangchuang Yu
bb_grid
Description
add grid lines
Usage
bb_grid(col = "lightgray", lty = par("lty"), lwd = par("lwd"), bg = TRUE)
Arguments
col |
line color |
lty |
line type |
lwd |
line width |
bg |
whether plot the grid lines as background |
Value
A modified bbplot object
Author(s)
Guangchuang Yu
bb_labs
Description
change labels for bbplot
Usage
bb_labs(title = NULL, sub = NULL, xlab = NULL, ylab = NULL)
bb_title(title)
bb_sub(sub)
bb_xlab(xlab)
bb_ylab(ylab)
Arguments
title |
title |
sub |
sub |
xlab |
xlab |
ylab |
ylab |
Details
setting one or several of 'title', 'sub', 'xlab', and 'ylab'
Value
A modified bbplot object
Author(s)
Guangchuang Yu
Examples
library(plotbb)
p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point(pch=19)
p + bb_labs(title = "hello", sub = "just for demo",
xlab="this is xlab", ylab = "this is ylab") +
bb_title("hello world") # last one rules
bb_legend
Description
Add legend for aesthetic mapping.
Usage
bb_legend(
position = "topright",
title = NULL,
aesthetic = "col",
pch = 19,
bty = "n",
...
)
Arguments
position |
legend position passed to |
title |
legend title. |
aesthetic |
currently only supports |
pch |
point shape used in legend. |
bty |
box type passed to |
... |
additional parameters passed to |
Value
A modified bbplot object
Author(s)
Guangchuang Yu
bb_scale_col_palette
Description
change col palette
Usage
bb_scale_col_palette(palette = NULL)
bb_scale_col_manual(values)
bb_scale_col_gradient(low = "#132B43", high = "#56B1F7")
Arguments
palette |
color palette |
values |
colors for discrete scale. |
low |
low color for continuous scale. |
high |
high color for continuous scale. |
Value
A modified bbplot object
Author(s)
Guangchuang Yu
aesthetic scales
Description
aesthetic scales
Usage
bb_scale_pch_manual(values)
bb_scale_lty_manual(values)
bb_scale_cex_manual(values)
bb_scale_cex_continuous(range = c(0.8, 1.6))
Arguments
values |
values used for mapping. |
range |
numeric length-2 range for continuous mapping. |
Value
A modified bbplot object
Author(s)
Guangchuang Yu
bb_theme
Description
bbplot theme
Usage
bb_theme(...)
bb_theme_expand(...)
bb_theme_grey(...)
bb_theme_deepblue(...)
Arguments
... |
parameters for graphics::par |
Details
setting visual details of bbplot
Value
A modified bbplot object
Author(s)
Guangchuang Yu
bbplot
Description
bbplot
Usage
bbplot(data, mapping = bb_aes())
Arguments
data |
data |
mapping |
variable mapping |
Details
a proof of concept for grammar of graphics based on base plot. The bbplot class contains data (input data), mapping (aesthetic mapping), layer (a list of plot layers), theme (theme setting) and labs (label setting, including title, subtitle, x and y labels).
Value
bbplot object
Author(s)
Guangchuang Yu
Examples
library(plotbb)
p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl)))
p + bb_grid(col='grey50', lty='dashed') + bb_point(pch=19)
bbplot_add
Description
Add custom objects to bbplot
Usage
bbplot_add(object, plot)
Arguments
object |
An object to add to the plot |
plot |
The bbplot object to add 'object' to |
Details
This generic allows you to add your own methods for adding custom objects to a bbplot object.
Value
A modified bbplot object
Author(s)
Guangchuang Yu
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- magrittr
set_bb_theme
Description
set bb_theme
Usage
set_bb_theme(theme)
Arguments
theme |
bb_theme |
Details
setting bb_theme for ordinary base plot command. It internally use par to set global graphic parameters. Users need to explictely call unset_bb_theme() to restore original setting.
Value
setting selected theme as default (has side effect and will affect other base plot)
Author(s)
Guangchuang Yu
Examples
library(plotbb)
set_bb_theme(bb_theme_deepblue)
bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point(pch=19)
unset_bb_theme
Description
unset bb_theme
Usage
unset_bb_theme()
Details
remove all the themes by set_bb_theme
Value
unset theme (i.e., restore par setting)
Author(s)
Guangchuang Yu