cat_offset {rbokeh} | R Documentation |
Add an offset to a categorical variable for Bokeh plotting.
cat_offset(x, offset)
x |
The categorical data to offset, a vector of categorical / factor data. |
offset |
A numeric vector of matching length of |
This function allows specification of plotting values in between two categorical values. Suppose, for example, a categorical axis has axis ticks ordered "a", "b", "c". Then plotting cat_offset("a", -0.5)
will plot a value halfway between "a" and "b", while plotting cat_offset("a", 0.5)
will plot a value halfway between "b" and "c".
figure(title = "Periodic Table", data = elements, xgrid = FALSE, ygrid = FALSE, xlab = "", ylab = "", xlim = as.character(1:18), ylim = c(" ", " ", " ", as.character(7:1)), height = 700, width = 1200) %>% ly_crect(cat_offset(group, group_offset), period, 0.9, 0.9, color = group_block, fill_alpha = 0.6, legend = FALSE, hover = list(name, atomic_number, group_block, atomic_mass, electronic_configuration)) %>% ly_text(cat_offset(group, sym_offset), period, text = symbol, font_style = "bold", font_size = "15pt", align = "left", baseline = "middle") %>% ly_text(cat_offset(group, sym_offset), cat_offset(period, 0.3), text = atomic_number_p, font_size = "9pt", align = "left", baseline = "middle") %>% ly_text(cat_offset(group, sym_offset), cat_offset(period, -0.2), text = name, font_size = "6pt", align = "left", baseline = "middle") %>% ly_text(cat_offset(group, sym_offset), cat_offset(period, -0.35), text = atomic_mass, font_size = "6pt", align = "left", baseline = "middle") %>% x_axis(axis = axis_spec(visible = FALSE)) %>% y_axis(axis = axis_spec(visible = FALSE))