Package 'plotbb'

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

Help Index


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


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

layer

Description

layer

Usage

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, ...)

Arguments

mapping

aesthetic mapping

data

layer data

...

addition parameter for the layer

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_scale_col_palette

Description

change col palette

Usage

bb_scale_col_palette(palette = NULL)

Arguments

palette

color palette

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)

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