R Interface for Bokeh

Authors: Ryan Hafen [aut, cre],Kenton Russell [ctb],Jonathan Owen [ctb],Barret Schloerke [ctb],Saptasrhi Guha [ctb],Continuum Analytics, Inc. [aut, cph]

Version: 0.5.1

License: MIT + file LICENSE

Description

A native R plotting library that provides a flexible declarative interface for creating interactive web-based graphics, backed by the Bokeh visualization library http://bokeh.pydata.org/.

Imports

htmlwidgets (>= 0.5), maps, methods, jsonlite, digest, hexbin, lazyeval, pryr, magrittr, ggplot2, scales, gistr

Suggests

testthat, data.table, lattice, lintr, roxygen2 (>= 5.0.0), packagedocs, latticeExtra

Enhances

shiny (>= 0.12)

rbokeh

rbokeh-package: rbokeh, rbokeh-package

rbokeh: R interface for Bokeh

R interface for creating plots in Bokeh. Bokeh by Continuum Analytics, http://bokeh.pydata.org/en/latest/

Details

For full documentation on the package, visit http://hafen.github.io/rbokeh

Plots

figure

Initialize a Bokeh figure

Usage

figure(data = NULL, width = NULL, height = NULL, title = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, padding_factor = 0.07, xgrid = TRUE, ygrid = TRUE, xaxes = "below", yaxes = "left", legend_location = "top_right", tools = c("pan", "wheel_zoom", "box_zoom", "reset", "save", "help"), theme = getOption("bokeh_theme"), toolbar_location = "above", h_symmetry = TRUE, v_symmetry = FALSE, logo = NULL, lod_factor = 10, lod_interval = 300, lod_threshold = NULL, lod_timeout = 500, webgl = FALSE, ...)

Arguments

data
data to be supplied to all layers, if the layer doesnt supply a data value
width
figure width in pixels
height
figure width in pixels
title
a title to display above the plot. - “title” is also the prefix for a set of Text Properties, so you can set the font for the title with the parameter text_font.
xlab
label for x axis
ylab
label for y axis
xlim
the extent of the plotting area in the x-dimension (will be computed automatically if not specified).
ylim
the extent of the plotting area in the y-dimension (will be computed automatically if not specified).
padding_factor
if limits are not specified, by what factor should the extents of the data be padded
xgrid
whether to draw x axis grid lines
ygrid
whether to draw y axis grid lines
xaxes
where to put x axis, or FALSE if no x axis ticks / labels
yaxes
where to put y axis, or FALSE if no y axis ticks / labels
legend_location
(top_right, top_left, bottom_left, bottom_right) the location where the legend should draw itself, or NULL to omit the legend
tools
character vector of interactivity tools options (acceptable values are: “pan”, “wheel_zoom”, “box_zoom”, “resize”, “crosshair”, “box_select”, “lasso_select”, “reset”, “save”, “help”). Additionally, tool functions can be called on a figure to specify more control - see the “See Also” section below for a list of tool functions. If NULL, the toolbar will not be drawn. If "" the toolbar will be drawn but no tools will be added by default.
theme
an rbokeh theme to use
toolbar_location
(above, below, left, right) Where the toolbar will be located. If set to NULL, no toolbar will be attached to the plot.
h_symmetry
(logical) Whether the total horizontal padding on both sides of the plot will be made equal (the left or right padding amount, whichever is larger).
v_symmetry
(logical) Whether the total vertical padding on both sides of the plot will be made equal (the top or bottom padding amount, whichever is larger).
logo
(normal, grey) What version of the Bokeh logo to display on the toolbar. If set to NULL, no logo will be displayed.
lod_factor
(integer) Decimation factor to use when applying level-of-detail decimation (see “Controlling level of detail”).
lod_interval
(integer) Interval (in ms) during which an interactive tool event will enable level-of-detail downsampling (see “Controlling level of detail”).
lod_threshold
(integer) A number of data points, above which level-of-detail downsampling may be performed by glyph renderers. Set to NULL to disable any level-of-detail downsampling (see “Controlling level of detail”).
lod_timeout
(integer) Timeout (in ms) for checking whether interactive tool events are still occurring. Once level-of-detail mode is enabled, a check is made every lod_timeout ms. If no interactive tool events have happened, level-of-detail mode is disabled (see “Controlling level of detail”).
webgl
(logical) should webgl be used for rendering?
parameters can be specified here that are available in theme_plot

Controlling level of detail

Although the HTML canvas can comfortably display tens or even hundreds of thousands of glyphs, doing so can have adverse affects on interactive performance. In order to accommodate large-ish (but not enormous) data sizes, Bokeh plots offer “Level of Detail” (LOD) capability in the client.

The basic idea is that during interactive operations (e.g., panning or zooming), the plot only draws some small fraction data points. This hopefully allows the general sense of the interaction to be preserved mid-flight, while maintaining interactive performance. See the lod_ parameters for information on how to control this.

Examples

figure() %>% ly_points(1:10)

See also

Layers to add to a figure: ly_abline; ly_annular_wedge; ly_annulus; ly_arc; ly_bezier; ly_boxplot; ly_contour; ly_crect; ly_curve; ly_density; ly_hist; ly_image_url; ly_image; ly_lines; ly_map; ly_multi_line; ly_oval; ly_patch; ly_points; ly_polygons; ly_quadratic; ly_quantile; ly_ray; ly_segments; ly_text; ly_wedge Tools to add to a figure: tool_box_select; tool_box_zoom; tool_crosshair; tool_lasso_select; tool_reset; tool_resize; tool_save; tool_wheel_zoom Other figure types: grid_plot; gmap

gmap

Initialize a Bokeh Google Map plot

Usage

gmap(lat = 0, lng = 0, zoom = 0, api_key = NULL, map_type = "hybrid", map_style = NULL, width = 480, height = 480, title = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, padding_factor = 0.07, xgrid = FALSE, ygrid = FALSE, xaxes = FALSE, yaxes = FALSE, tools = c("pan", "wheel_zoom", "save"), theme = getOption("bokeh_theme"))

Arguments

lat
latitude where the map should be centered
lng
longitude where the map should be centered
zoom
initial zoom level to use when displaying the map
api_key
Google Maps API key
map_type
map type to use for the plot - one of “hybrid”, “satellite”, “roadmap”, “terrain”
map_style
a json string of a Google Maps style - see gmap_style
width
figure width in pixels
height
figure width in pixels
title
a title to display above the plot. - “title” is also the prefix for a set of Text Properties, so you can set the font for the title with the parameter text_font.
xlab
label for x axis
ylab
label for y axis
xlim
the extent of the plotting area in the x-dimension (will be computed automatically if not specified).
ylim
the extent of the plotting area in the y-dimension (will be computed automatically if not specified).
padding_factor
if limits are not specified, by what factor should the extents of the data be padded
xgrid
whether to draw x axis grid lines
ygrid
whether to draw y axis grid lines
xaxes
where to put x axis, or FALSE if no x axis ticks / labels
yaxes
where to put y axis, or FALSE if no y axis ticks / labels
tools
character vector of interactivity tools options (acceptable values are: “pan”, “wheel_zoom”, “box_zoom”, “resize”, “crosshair”, “box_select”, “lasso_select”, “reset”, “save”, “help”). Additionally, tool functions can be called on a figure to specify more control - see the “See Also” section below for a list of tool functions. If NULL, the toolbar will not be drawn. If "" the toolbar will be drawn but no tools will be added by default.
theme
an rbokeh theme to use

Note

This can be used in the same way as figure, adding layers on top of the Google Map. There is an open issue documenting points appearing to sometimes be a few pixels off from their intended location. Google has its own terms of service for using Google Maps API and any use of rbokeh with Google Maps must be within Googles Terms of Service

Examples

# custom map style
gmap(lat = 40.74, lng = -73.95, zoom = 11,
  width = 600, height = 600,
  map_style = gmap_style("blue_water"))
## Not run: 
# gmap(title = "NYC taxi pickups January 2013",
#   lat = 40.74, lng = -73.95, zoom = 11,
#   map_type = "roadmap", width = 1000, height = 800) %>%
#   ly_hexbin(nyctaxihex, alpha = 0.5,
#     palette = "Spectral10", trans = log, inv = exp)
# ## End(Not run)

See also

gmap_style

grid_plot

Create a Bokeh grid plot from a list of Bokeh figures

Usage

grid_plot(figs, width = NULL, height = NULL, nrow = 1, ncol = 1, byrow = TRUE, xlim = NULL, ylim = NULL, logo = NULL, same_axes = FALSE, simplify_axes = TRUE, y_margin = NULL, x_margin = NULL, link_data = FALSE)

Arguments

figs
list of Bokeh figures - see details for what is acceptable
width
width of the entire grid plot in pixels - if NULL, the sum of the grid widths of columns will be used - if not NULL, the widths of the plots will be proportionately shrunk to meet the specified width
height
height of the entire grid plot in pixels - if NULL, the sum of the grid heights of rows will be used - if not NULL, the heights of the plots will be proportionately shrunk to meet the specified height
nrow
number of rows in the grid
ncol
number of columns in the grid
byrow
populate the grid by row according to the order of figure elements supplied in params
xlim
the extent of the plotting area in the x-dimension to be applied to every panel (original individual panel limits will be honored if not specified).
ylim
the extent of the plotting area in the y-dimension to be applied to every panel (original individual panel limits will be honored if not specified).
logo
(normal, grey) What version of the Bokeh logo to display on the toolbar. If set to NULL, no logo will be displayed.
same_axes
logical or vector of two logicals specifying whether the x and/or y axis limits should be the same for each plot in the grid
simplify_axes
logical or vector of logicals specifying whether to simply the x and/or y axes (only show the axes along the bottom and left sides of the grid) - only valid if same_axes is TRUE for the axis
x_margin, y_margin
specify the margin space in pixels to be left for axes when using simplify_axes=TRUE
link_data
logical - should an attempt be made to join the data sources of each plot for linked brushing? (see details)

Details

The figs parameter can either be a list of figures or a list of lists of figures. If the latter, the list structure will determine the layout, with each super-list of figures defining a single row of the grid. If the former, the parameters nrow and ncol and byrow are used to determine the layout. The grid is from top to bottom left to right.

If link_data is TRUE, then an effort will be made to link all data sources that are common among the different figures in the plot. Note that at this point, only data sources that are specified in the data argument to the different layer functions are checked.

Examples

idx <- split(1:150, iris$Species)
figs <- lapply(idx, function(x) {
  figure(width = 300, height = 300) %>%
    ly_points(Sepal.Length, Sepal.Width, data = iris[x, ],
      hover = list(Sepal.Length, Sepal.Width))
})

# 1 row, 3 columns
grid_plot(figs)
# specify xlim and ylim to be applied to all panels
grid_plot(figs, xlim = c(4, 8), ylim = c(1.5, 4.5))
# unnamed list will remove labels
grid_plot(unname(figs))
# 2 rows, 2 columns
grid_plot(figs, nrow = 2)
# x and y axis with same (and linked) limits
grid_plot(figs, same_axes = TRUE)
# x axis with same (and linked) limits
grid_plot(figs, same_axes = c(TRUE, FALSE), nrow = 2)
# x axis with same (and linked) limits and custom xlim
grid_plot(figs, same_axes = c(TRUE, FALSE), xlim = c(5, 7), nrow = 2)
# send lists instead of specifying nrow and ncol
grid_plot(list(
  c(list(figs[[1]]), list(figs[[3]])),
  c(list(NULL), list(figs[[2]]))
))
# a null entry will be skipped in the grid
figs2 <- figs
figs2[1] <- list(NULL)
grid_plot(figs2, nrow = 2)
# with themes
grid_plot(figs) %>%
  theme_title(text_color = "red") %>%
  theme_plot(background_fill_color = "#E6E6E6",
    outline_line_color = "white") %>%
  theme_grid(c("x", "y"), grid_line_color = "white",
    minor_grid_line_color = "white",
    minor_grid_line_alpha = 0.4) %>%
  theme_axis(c("x", "y"), axis_line_color = "white",
    major_label_text_color = "#7F7F7F",
    major_tick_line_color = "#7F7F7F",
    minor_tick_line_alpha = 0, num_minor_ticks = 2)
# themes again
grid_plot(figs) %>%
  set_theme(bk_ggplot_theme)
# link data across plots in the grid (try box_select tool)
# (data sources must be the same)
tools <- c("pan", "wheel_zoom", "box_zoom", "box_select", "reset")
p1 <- figure(tools = tools, width = 500, height = 500) %>%
  ly_points(Sepal.Length, Sepal.Width, data = iris, color = Species)
p2 <- figure(tools = tools, width = 500, height = 500) %>%
  ly_points(Petal.Length, Petal.Width, data = iris, color = Species)
grid_plot(list(p1, p2), same_axes = TRUE, link_data = TRUE)

Layer Functions

ly_annular_wedge

Add an “annular_wedge” layer to a Bokeh figure

Usage

ly_annular_wedge(fig, x, y = NULL, data = figure_data(fig), inner_radius = 0.1, outer_radius = 0.3, start_angle = 0, end_angle = 2 * pi, direction = "anticlock", color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
inner_radius
values or field name of inner radii
outer_radius
values or field name of outer radii
start_angle
the angles to start the annular wedges, in radians, as measured from the horizontal
end_angle
the angles to end the annular wedges, in radians, as measured from the horizontal
direction
direction to turn between starting and ending angles (“anticlock”, “clock”)
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

rescale <- function(x)
  (x - min(x)) / diff(range(x))
figure() %>%
  ly_annular_wedge(Sepal.Length, Sepal.Width, data = iris,
    end_angle = rescale(Petal.Length) * 2 * pi, color = Species,
    inner_radius = 0.1, outer_radius = 0.15, alpha = 0.5,
    hover = Species)

See also

Other layer functions: ly_abline, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_annulus

Add an “annulus” layer to a Bokeh figure

Usage

ly_annulus(fig, x, y = NULL, data = figure_data(fig), inner_radius = 0.1, outer_radius = 0.2, color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
inner_radius
values or field name of inner radii
outer_radius
values or field name of outer radii
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

rescale <- function(x)
  (x - min(x)) / diff(range(x))
figure() %>%
  ly_annulus(Sepal.Length, Sepal.Width, data = iris,
    color = Species, hover = Species, alpha = 0.5,
    outer_radius = rescale(Petal.Length) * 0.3,
    inner_radius = rescale(Petal.Length) * 0.1)

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_arc

Add an “arc” layer to a Bokeh figure

Usage

ly_arc(fig, x, y = NULL, data = figure_data(fig), color = NULL, alpha = 1, width = 2, type = 1, radius = 0.2, start_angle = 0, end_angle = 2 * pi, direction = "anticlock", legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
radius
values or field name of arc radii
start_angle
values or field name of starting angles
end_angle
values or field name of ending angles
direction
direction to turn between starting and ending angles (“anticlock”, “clock”)
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

rescale <- function(x)
  (x - min(x)) / diff(range(x))
figure() %>%
  ly_arc(Sepal.Length, Sepal.Width, data = iris,
    end_angle = rescale(Petal.Length) * 2 * pi, color = Species,
    alpha = 0.5)

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_bezier

Add a “bezier” layer to a Bokeh figure

Draws Bezier curves with the given starting, ending, and control points.

Usage

ly_bezier(fig, x0, y0, x1, y1, cx0, cy0, cx1, cy1, data = figure_data(fig), color = "black", alpha = 1, width = 1, type = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x0
values or field name of starting x coordinates
y0
values or field name of starting y coordinates
x1
values or field name of ending x coordinates
y1
values or field name of ending y coordinates
cx0
values or field name of first control point x coordinates
cy0
values or field name of first control point y coordinates
cx1
values or field name of second control point x coordinates
cy1
values or field name of second control point y coordinates
data
an optional data frame, providing the source for start, end, and control point intputs, as well as other glyph properties
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_crect

Add a “crect” (centered rectangle) layer to a Bokeh figure

Usage

ly_crect(fig, x, y = NULL, data = figure_data(fig), width = 1, height = 1, angle = 0, dilate = FALSE, color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs xleft, ybottom, xright, ytop, and other glyph properties
width
values or field name of widths
height
values or field name of heights
angle
values or field name of rotation angles
dilate
logical - whether to dilate pixel distance computations when drawing
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

# prepare data
elements <- subset(elements, !is.na(group))
elements$group <- as.character(elements$group)
elements$period <- as.character(elements$period)

# add colors for groups
metals <- c("alkali metal", "alkaline earth metal", "halogen",
  "metal", "metalloid", "noble gas", "nonmetal", "transition metal")
colors <- c("#a6cee3", "#1f78b4", "#fdbf6f", "#b2df8a", "#33a02c",
  "#bbbb88", "#baa2a6", "#e08e79")
elements$color <- colors[match(elements$metal, metals)]
elements$type <- elements$metal

# make coordinates for labels
elements$symx <- paste(elements$group, ":0.1", sep = "")
elements$numbery <- paste(elements$period, ":0.8", sep = "")
elements$massy <- paste(elements$period, ":0.15", sep = "")
elements$namey <- paste(elements$period, ":0.3", sep = "")

# create figure
p <- figure(title = "Periodic Table", tools = "",
  ylim = as.character(c(7:1)), xlim = as.character(1:18),
  xgrid = FALSE, ygrid = FALSE, xlab = "", ylab = "",
  height = 600, width = 1200) %>%

# plot rectangles
ly_crect(group, period, data = elements, 0.9, 0.9,
  fill_color = color, line_color = color, fill_alpha = 0.6,
  hover = list(name, atomic.number, type, atomic.mass,
    electronic.configuration)) %>%

# add symbol text
ly_text(symx, period, text = symbol, data = elements,
  font_style = "bold", font_size = "15pt",
  align = "left", baseline = "middle") %>%

# add atomic number text
ly_text(symx, numbery, text = atomic.number, data = elements,
  font_size = "9pt", align = "left", baseline = "middle") %>%

# add name text
ly_text(symx, namey, text = name, data = elements,
  font_size = "6pt", align = "left", baseline = "middle") %>%

# add atomic mass text
ly_text(symx, massy, text = atomic.mass, data = elements,
  font_size = "6pt", align = "left", baseline = "middle")

p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_image

Add an “image” layer to a Bokeh figure

Draws a grid of rectangles with colors corresponding to the values in z

Usage

ly_image(fig, z, rows, byrow = TRUE, x = 0, y = 0, dw = 1, dh = 1, palette = "Spectral10", dilate = FALSE, lname = NULL, lgroup = NULL)

Arguments

fig
figure to modify
z
matrix or vector of image values
rows
if z is a vector, how many rows should be used in treating it as a matrix
byrow
if z is a vector, should it be turned into a matrix by row
x
lower left x coordinates
y
lower left y coordinates
dw
image width distances
dh
image height distances
palette
name of color palette to use for color ramp (see here for acceptable values)
dilate
logical - whether to dilate pixel distance computations when drawing
lname
layer name
lgroup
layer group

Examples

p <- figure(xlim = c(0, 1), ylim = c(0, 1), title = "Volcano") %>%
  ly_image(volcano) %>%
  ly_contour(volcano)
p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_image_url

Add an “image_url” layer to a Bokeh figure

Renders raster images from URLs at provided coordinates

Usage

ly_image_url(fig, x = 0, y = 0, data = figure_data(fig), w = 10, h = 10, image_url, dilate = TRUE, anchor = "top_left", angle = 0, lname = NULL, lgroup = NULL)

Arguments

fig
figure to modify
x
x coordinates
y
y coordinates
data
an optional data frame, providing the source for inputs x, y, and other properties
w, h
values or field names of width and height of image
image_url
values or field name of image URLs
dilate
logical - whether to dilate pixel distance computations when drawing
anchor
where the image is anchored to with respect to x and y
angle
values or field name of the angle to rotate the image, in radians
lname
layer name
lgroup
layer group

Examples

url <- c("  http://bokeh.pydata.org/en/latest/_static/images/logo.png",
  "http://developer.r-project.org/Logo/Rlogo-4.png")

ss <- seq(0, 2*pi, length = 13)[-1]
ws <- runif(12, 2.5, 5) * rep(c(1, 0.8), 6)

imgdat <- data.frame(
  x = sin(ss) * 10, y = cos(ss) * 10,
  w = ws, h = ws * rep(c(1, 0.76), 6),
  url = rep(url, 6)
)

p <- figure(xlab = "x", ylab = "y") %>%
  ly_image_url(x, y, w = w, h = h, image_url = url, data = imgdat,
    anchor = "center") %>%
  ly_lines(sin(c(ss, ss[1])) * 10, cos(c(ss, ss[1])) * 10,
    width = 15, alpha = 0.1)
p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_lines

Add a “lines” layer to a Bokeh figure Draws lines with the given coordinates.

Usage

ly_lines(fig, x, y = NULL, data = figure_data(fig), group = NULL, color = "black", type = 1, width = 1, alpha = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of line x coordinates
y
values or field name of line y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
group
values or field name of a grouping variable to break lines up by
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
width
stroke width in units of pixels
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

z <- lm(dist ~ speed, data = cars)
p <- figure() %>%
  ly_points(cars, hover = cars) %>%
  ly_lines(lowess(cars), legend = "lowess") %>%
  ly_abline(z, type = 2, legend = "lm", width = 2)
p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_multi_line

Add a “multi_line” layer to a Bokeh figure

Draws multiple lines with the given lists of coordinates.

Usage

ly_multi_line(fig, xs, ys, color = "black", alpha = 1, width = 1, type = 1, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
xs
list of vectors of x coordinates
ys
list of vectors of y coordinates
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_oval

Add an “oval” layer to a Bokeh figure

Usage

ly_oval(fig, x, y = NULL, data = figure_data(fig), width = 0.1, height = 0.1, angle = 0, color = NULL, alpha = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
width
values or field name of widths
height
values or field name of heights
angle
values or field name of rotation angles
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_patch

Add a “patch” layer to a Bokeh figure

Usage

ly_patch(fig, x, y, data = figure_data(fig), color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of patch x coordinates
y
values or field name of patch y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Note

This function is included for completeness as it maps to Bokehs patch glyph, but the same and more functionality can be obtained with ly_polygons.

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_points

Add a “points” layer to a Bokeh figure

Usage

ly_points(fig, x, y = NULL, data = figure_data(fig), glyph = 21, color = NULL, alpha = 1, size = 10, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
glyph
value(s) or field name of the glyph to use (see point_types)
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
size
size of the glyph in screen units
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

figure() %>%
  ly_points(Sepal.Length, Sepal.Width, data = iris,
    color = Species, glyph = Species,
    hover = list(Sepal.Length, Sepal.Width))
# custom hover
mtcars$model <- row.names(mtcars)
figure() %>%
  ly_points(disp, mpg, data = mtcars, color = cyl,
    hover = "This <strong>@model</strong><br>has @hp horsepower!")
z <- lm(dist ~ speed, data = cars)
p <- figure() %>%
  ly_points(cars, hover = cars) %>%
  ly_lines(lowess(cars), legend = "lowess") %>%
  ly_abline(z, type = 2, legend = "lm", width = 2)
p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_polygons

Add a “polygons” layer to a Bokeh figure

Usage

ly_polygons(fig, xs, ys, group = NULL, data = figure_data(fig), color = NULL, alpha = 1, hover = NULL, url = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
xs
vector or list of values or field name of polygon x coordinates - see details
ys
vector or list of values or field name of polygon y coordinates - see details
group
vector or field name of grouping variable - see details
data
an optional data frame, providing the source for inputs xs, ys, group, and other glyph properties
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Details

xs and ys can be a list of vectors, each element for one polygon to be drawn, or can be vectors with the group argument specifying how to break them up into individual polygons.

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_quadratic

Add a “quadratic” layer to a Bokeh figure

Draws quadratic curves with the given starting, ending, and control points.

Usage

ly_quadratic(fig, x0, y0, x1, y1, cx, cy, data = figure_data(fig), color = "black", alpha = 1, width = 1, type = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x0
values or field name of starting x coordinates
y0
values or field name of starting y coordinates
x1
values or field name of ending x coordinates
y1
values or field name of ending y coordinates
cx
values or field name of control point x coordinates
cy
values or field name of control point y coordinates
data
an optional data frame, providing the source for start, end, and control point intputs, as well as other glyph properties
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_ray

Add a “ray” layer to a Bokeh figure

Draws line segments starting at the given coordinate and extending the given length at the given angle.

Usage

ly_ray(fig, x, y = NULL, data = figure_data(fig), length = NULL, angle = 0, color = "black", type = 1, width = 1, alpha = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
length
values or field name of ray lengths in screen units
angle
values or field name of ray angles
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
width
stroke width in units of pixels
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_rect, ly_segments, ly_text, ly_wedge

ly_rect

Add a “rect” layer to a Bokeh figure

Usage

ly_rect(fig, xleft, ybottom, xright, ytop, data = figure_data(fig), color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
xleft
values or field name of left edges
ybottom
values or field name of bottom edges
xright
values or field name of right edges
ytop
values or field name of top edges
data
an optional data frame, providing the source for inputs xleft, ybottom, xright, ytop, and other glyph properties
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_segments, ly_text, ly_wedge

ly_segments

Add a “segments” layer to a Bokeh figure

Draws line segments with the given starting and ending coordinates.

Usage

ly_segments(fig, x0, y0, x1, y1, data = figure_data(fig), color = "black", alpha = 1, width = 1, type = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x0
values or field name of starting x coordinates
y0
values or field name of starting y coordinates
x1
values or field name of ending x coordinates
y1
values or field name of ending y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_text, ly_wedge

ly_text

Add a “text” layer to a Bokeh figure

Usage

ly_text(fig, x, y = NULL, text = NULL, data = figure_data(fig), color = "black", alpha = 1, angle = 0, align = NULL, baseline = NULL, font = NULL, font_size = NULL, font_style = NULL, x_offset = NULL, y_offset = NULL, legend = NULL, lname = NULL, lgroup = NULL)

Arguments

fig
figure to modify
x
x coordinates of text anchors
y
y coordinates of text anchors
text
text values to render
data
an optional data frame, providing the source for inputs x, y, text, and other glyph properties
color
text color values for the text
alpha
text alpha values for the text
angle
angle to rotate the text in radians
align
text align values for the text (“left”, “right”, “center”)
baseline
text baseline values for the text (“top”, “middle”, “bottom”, “alphabetic”, “hanging”)
font
text font values for the text
font_size
text font size values for the text
font_style
text font style values for the text (“normal”, “italic”, “bold”)
x_offset
offset values to apply to the x-coordinates
y_offset
offset values to apply to the y-coordinates
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Examples

# prepare data
elements <- subset(elements, !is.na(group))
elements$group <- as.character(elements$group)
elements$period <- as.character(elements$period)

# add colors for groups
metals <- c("alkali metal", "alkaline earth metal", "halogen",
  "metal", "metalloid", "noble gas", "nonmetal", "transition metal")
colors <- c("#a6cee3", "#1f78b4", "#fdbf6f", "#b2df8a", "#33a02c",
  "#bbbb88", "#baa2a6", "#e08e79")
elements$color <- colors[match(elements$metal, metals)]
elements$type <- elements$metal

# make coordinates for labels
elements$symx <- paste(elements$group, ":0.1", sep = "")
elements$numbery <- paste(elements$period, ":0.8", sep = "")
elements$massy <- paste(elements$period, ":0.15", sep = "")
elements$namey <- paste(elements$period, ":0.3", sep = "")

# create figure
p <- figure(title = "Periodic Table", tools = "",
  ylim = as.character(c(7:1)), xlim = as.character(1:18),
  xgrid = FALSE, ygrid = FALSE, xlab = "", ylab = "",
  height = 600, width = 1200) %>%

# plot rectangles
ly_crect(group, period, data = elements, 0.9, 0.9,
  fill_color = color, line_color = color, fill_alpha = 0.6,
  hover = list(name, atomic.number, type, atomic.mass,
    electronic.configuration)) %>%

# add symbol text
ly_text(symx, period, text = symbol, data = elements,
  font_style = "bold", font_size = "15pt",
  align = "left", baseline = "middle") %>%

# add atomic number text
ly_text(symx, numbery, text = atomic.number, data = elements,
  font_size = "9pt", align = "left", baseline = "middle") %>%

# add name text
ly_text(symx, namey, text = name, data = elements,
  font_size = "6pt", align = "left", baseline = "middle") %>%

# add atomic mass text
ly_text(symx, massy, text = atomic.mass, data = elements,
  font_size = "6pt", align = "left", baseline = "middle")

p

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_wedge

ly_wedge

Add a “wedge” layer to a Bokeh figure

Usage

ly_wedge(fig, x, y = NULL, data = figure_data(fig), radius = 0.3, start_angle = 0, end_angle = 2 * pi, direction = "anticlock", color = NULL, alpha = 1, hover = NULL, url = NULL, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
values or field name of center x coordinates
y
values or field name of center y coordinates
data
an optional data frame, providing the source for inputs x, y, and other glyph properties
radius
values or field name of wedge radii
start_angle
the angles to start the wedges, in radians, as measured from the horizontal
end_angle
the angles to end the wedges, in radians, as measured from the horizontal
direction
direction to turn between starting and ending angles (“anticlock”, “clock”)
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
hover
a data frame of variables to be displayed when hovering over the glyph or a vector of variable names that can be found and extracted from the data argument
url
a string of URLs or a single string that references a variable name (via @var_name) that can be found and extracted from the data argument
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

rescale <- function(x)
  (x - min(x)) / diff(range(x))
figure() %>%
  ly_wedge(Sepal.Length, Sepal.Width, data = iris,
    end_angle = rescale(Petal.Length) * 2 * pi, color = Species,
    radius = 0.15, alpha = 0.5,
    hover = Species)

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text

Higher-Level Layer Functions

ly_quantile

Add a “quantile” layer to a Bokeh figure

Draws quantiles

Usage

ly_quantile(fig, x, group = NULL, data = figure_data(fig), probs = NULL, distn = stats::qunif, ncutoff = 200, color = NULL, alpha = 1, legend = TRUE, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
numeric vector or field name of variable to compute sample quantiles for
group
values or field name of a grouping variable to break quantile computations up by
data
an optional data frame, providing the source for x
probs
numeric vector of probabilities with values in [0,1] at which to compute quantiles - if NULL, every point of x is a quantile
distn
quantile function to use on the x-axis (e.g. qnorm) - default is qunif,
ncutoff
if the length of x exceeds this value and probs is not specified, compute quantiles at ncutoff points
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
legend
either a logical specifying not to plot a legend for this layer (FALSE) or a string indicating the name of the legend entry for this layer (note that when mapping plot attributes to variables in data, a legend is automatically created and does not need to be specified - see “Mapped plot attributes and legends” below)
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Mapped plot attributes and legends

When specifying an input data frame for a layer through the data argument, columns of data can be used to specify various plot attributes such as color, etc. For example, with ly_points(…, data = iris, color = Species), the Species variable is used to determine how to color the points. Here, Species is “mapped” to the color attribute. Both continuous and categorical variables can be mapped. In the case of continuous variables, the range is cut into slices and attributes are applied to each interval. The mapping from the values of the variable to the actual plot attributes is determined based on the theme.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

figure(legend_location = "top_left") %>%
  ly_quantile(Sepal.Length, group = Species, data = iris)

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_density

Add a “density” layer to a Bokeh figure

Draws a kernel density estimate

Usage

ly_density(fig, x, data = figure_data(fig), bw = "nrd0", adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine"), weights = NULL, window = kernel, n = 512, cut = 3, na.rm = FALSE, color = "black", alpha = 1, width = 1, type = 1, legend = NULL, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x, bw, adjust, kernel, weights, window, n, cut, na.rm
parameters passed to density
data
an optional data frame, providing the source for x
color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
alpha
transparency value for the line between 0 (transparent) and 1 (opaque)
width
stroke width in units of pixels
type
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use
legend
text to display in the legend entry for the density line
lname
layer name
lgroup
layer group
additional parameters for fine control over line properties (see “Additional parameters” below)

Additional parameters

line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
an integer between 1 and 6 matching the lty property in par or an array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

h <- figure(width = 600, height = 400) %>%
  ly_hist(eruptions, data = faithful, breaks = 40, freq = FALSE) %>%
  ly_density(eruptions, data = faithful)
h

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_hist, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_hist

Add a “hist” layer to a Bokeh figure

Draws a histogram

Usage

ly_hist(fig, x, data = figure_data(fig), breaks = "Sturges", freq = TRUE, include.lowest = TRUE, right = TRUE, color = NULL, alpha = 1, lname = NULL, lgroup = NULL, ...)

Arguments

fig
figure to modify
x
either a vector to be passed to hist or an object of class “histogram”
data
an optional data frame, providing the source for x
breaks, freq, include.lowest, right
parameters passed to hist
color
color for the glyph - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo - for glyphs with both fill and line properties, see “Handling color” below
alpha
the alpha transparency of the glyph between 0 (transparent) and 1 (opaque) - if glyph has both fill and color properties, see “Handling alpha” below
lname
layer name
lgroup
layer group
additional parameters for fine control over fill and line properties (see “Additional parameters” below)

Handling color

The color parameter is a high-level plot attribute that provides default behavior for coloring glyphs.

  • When using a glyph that only has line properties, this will be the color of the line.
  • When using a glyph that has has line and fill properties, this will be the color of the line and the fill, with the alpha level of the fill reduced by 50%.
  • If full control over fill and line color is desired, the fill_color and line_color attributes can be specified explicitly and will override color.

When color is NULL and fill_color or line_color are not specified, the color will be chosen from the theme.

Handling alpha

The alpha is a high-level plot attribute that sets the transparency of the glyph being plotted.

  • When using a glyph that only has line properties, this will be the alpha of the line.
  • When using a glyph that has has line and fill properties, this will be the alpha of the line and the alpha of the fill will be set to 50% of this value.
  • Individual fill and line alpha can be specified with fill_alpha and line_alpha and will override alpha.

Additional parameters

fill_color
color to use to fill the glyph with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
fill_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_color
color to use to stroke lines with - a hex code (with no alpha) or any of the 147 named CSS colors, e.g green, indigo
line_width
stroke width in units of pixels
line_alpha
transparency value between 0 (transparent) and 1 (opaque)
line_join
how path segments should be joined together miter round bevel
line_cap
how path segments should be terminated butt round square
line_dash
array of integer pixel distances that describe the on-off pattern of dashing to use

Examples

h <- figure(width = 600, height = 400) %>%
  ly_hist(eruptions, data = faithful, breaks = 40, freq = FALSE) %>%
  ly_density(eruptions, data = faithful)
h

See also

Other layer functions: ly_abline, ly_annular_wedge, ly_annulus, ly_arc, ly_bar, ly_bezier, ly_boxplot, ly_contour, ly_crect, ly_curve, ly_density, ly_image_url, ly_image, ly_lines, ly_map, ly_multi_line, ly_oval, ly_patch, ly_points, ly_polygons, ly_quadratic, ly_quantile, ly_ray, ly_rect, ly_segments, ly_text, ly_wedge

ly_hexbin

Add a “hexbin” layer to a Bokeh figure

Usage

ly_hexbin(fig, x, y = NULL, data = figure_data(fig), xbins = 30, shape = 1, xbnds = NULL, ybnds = NULL, style = "colorscale", trans = NULL, inv = NULL, lname = NULL, palette = "RdYlGn11", line = FALSE, alpha = 1, hover = TRUE)

Arguments

fig
figure to modify
x
values or field name of center x coordinates to be binned
y
values or field name of center y coordinates to be binned
data
an optional data frame, providing the source for x and y
xbins, shape, xbnds, ybnds
parameters passed to hexbin
style
type of plotting for hexbins (see grid.hexagons) - “colorramp” and “lattice” are currently supported
trans, inv
transformation and inverse transformation function for the bin counts
lname
layer name
palette
name of color palette to use for color ramp (see here for acceptable values)
line
logical - should hexagons have an outline?
alpha
the alpha transparency of the hexagons between 0 (transparent) and 1 (opaque)
hover
logical - should a hover tool be added to show the count in each hexagon?

Examples

figure() %>% ly_hexbin(rnorm(10000), rnorm(10000))