ly_text: Add a "text" layer to a Bokeh figure

Description Usage Arguments Mapped plot attributes and legends See Also Examples

View source: R/layer_text.R

Description

Add a "text" layer to a Bokeh figure

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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.

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()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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

rbokeh documentation built on Aug. 4, 2021, 1:06 a.m.