Title: | Grammar of Graphics for 'base' Plot |
---|---|
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. |
Authors: | Guangchuang Yu [aut, cre, cph] |
Maintainer: | Guangchuang Yu <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.0.6 |
Built: | 2024-11-03 05:58:06 UTC |
Source: | https://github.com/cran/plotbb |
convert a base plot function to a bbplot object
as.bbplot(fun)
as.bbplot(fun)
fun |
a function that plot something in base graphics |
the base plot function will be plotted as a canvas and users can apply theme and add layers to it
A bbplot object
Guangchuang Yu
aesthetic mapping
bb_aes(x, y, ...)
bb_aes(x, y, ...)
x |
x variable |
y |
y variable |
... |
other mappings |
aesthetic mapping for bbplot
enquo expression describing variables mapping to aesthetic attributes
Guangchuang Yu
add grid lines
bb_grid(col = "lightgray", lty = par("lty"), lwd = par("lwd"), bg = TRUE)
bb_grid(col = "lightgray", lty = par("lty"), lwd = par("lwd"), bg = TRUE)
col |
line color |
lty |
line type |
lwd |
line width |
bg |
whether plot the grid lines as background |
A modified bbplot object
Guangchuang Yu
change labels for bbplot
bb_labs(title = NULL, sub = NULL, xlab = NULL, ylab = NULL) bb_title(title) bb_sub(sub) bb_xlab(xlab) bb_ylab(ylab)
bb_labs(title = NULL, sub = NULL, xlab = NULL, ylab = NULL) bb_title(title) bb_sub(sub) bb_xlab(xlab) bb_ylab(ylab)
title |
title |
sub |
sub |
xlab |
xlab |
ylab |
ylab |
setting one or several of 'title', 'sub', 'xlab', and 'ylab'
A modified bbplot object
Guangchuang Yu
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
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
layer
bb_lm(mapping = NULL, data = NULL, ...) bb_point(mapping = NULL, data = NULL, position = "identity", ...) bb_text(mapping = NULL, data = NULL, ...) bb_tile(mapping = NULL, data = NULL, ...)
bb_lm(mapping = NULL, data = NULL, ...) bb_point(mapping = NULL, data = NULL, position = "identity", ...) bb_text(mapping = NULL, data = NULL, ...) bb_tile(mapping = NULL, data = NULL, ...)
mapping |
aesthetic mapping |
data |
layer data |
... |
addition parameter for the layer |
position |
one of 'identity' or 'jitter' |
bbplot layers
A modified bbplot object
Guangchuang Yu
library(plotbb) p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point() + bb_lm(bb_aes(group=cyl), lwd=2)
library(plotbb) p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point() + bb_lm(bb_aes(group=cyl), lwd=2)
change col palette
bb_scale_col_palette(palette = NULL)
bb_scale_col_palette(palette = NULL)
palette |
color palette |
A modified bbplot object
Guangchuang Yu
bbplot theme
bb_theme(...) bb_theme_expand(...) bb_theme_grey(...) bb_theme_deepblue(...)
bb_theme(...) bb_theme_expand(...) bb_theme_grey(...) bb_theme_deepblue(...)
... |
parameters for graphics::par |
setting visual details of bbplot
A modified bbplot object
Guangchuang Yu
bbplot
bbplot(data, mapping = bb_aes())
bbplot(data, mapping = bb_aes())
data |
data |
mapping |
variable mapping |
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).
bbplot object
Guangchuang Yu
library(plotbb) p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) p + bb_grid(col='grey50', lty='dashed') + bb_point(pch=19)
library(plotbb) p <- bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) p + bb_grid(col='grey50', lty='dashed') + bb_point(pch=19)
set bb_theme
set_bb_theme(theme)
set_bb_theme(theme)
theme |
bb_theme |
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.
setting selected theme as default (has side effect and will affect other base plot)
Guangchuang Yu
library(plotbb) set_bb_theme(bb_theme_deepblue) bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point(pch=19)
library(plotbb) set_bb_theme(bb_theme_deepblue) bbplot(mtcars, bb_aes(mpg, disp, col=factor(cyl))) + bb_point(pch=19)
unset bb_theme
unset_bb_theme()
unset_bb_theme()
remove all the themes by set_bb_theme
unset theme (i.e., restore par setting)
Guangchuang Yu