spec {rbokeh} | R Documentation |
Provide additional specification information about a Bokeh plot attribute.
spec(x, domain = NULL, range = NULL, transform = NULL, units = "screen", exponent = 0.5, unknown = "lightgray")
x |
Data / variable / expression to add specification information to. |
domain |
The domain of |
range |
The range of the mapping to be made from |
transform |
An optional string specifying a JavaScript transform to be applied to the data in the browser, the result of which will be the attribute value(s) used in rendering. See examples below. |
units |
The units according which to treat the attribute. One of 'screen' or 'data'. If 'screen', the value of |
exponent |
When |
unknown |
The color to use for values of |
# no custom spec figure() %>% ly_points(x = Sepal.Width, y = Sepal.Length, color = spec(Species, range = c("red", "green", "blue")), data = iris) # specifying a custom mapping for color figure() %>% ly_points(x = Sepal.Width, y = Sepal.Length, color = spec(Species, range = c("red", "green", "blue")), data = iris) # explicitly specifying which values correspond to which color figure() %>% ly_points(x = Sepal.Width, y = Sepal.Length, color = spec(Species, domain = c("virginica", "versicolor", "setosa"), range = c("red", "blue", "green")), data = iris) # unmapped values are plotted in gray (with default theme) iris$Species2 <- as.character(iris$Species) iris$Species2[1:20] <- "unknown" figure() %>% ly_points(x = Sepal.Width, y = Sepal.Length, color = spec(Species2, domain = c("virginica", "versicolor", "setosa"), range = c("red", "blue", "green")), data = iris) # specifying "screen" vs. "data" units figure() %>% ly_oval(Sepal.Length, Sepal.Width, width = spec(15, units = "screen"), height = spec(30, units = "screen"), angle = pi / 4, data = iris, color = Species) # example using custom JS transforms for every specified plot attribute # random size, line width, and color # note that JS transforms are automatically vectorized if provided as a string figure() %>% ly_points(rnorm(100), rnorm(100), size = spec(1:100, transform = "return Math.random() * 50 + 10;"), line_width = spec(1:100, transform = "return Math.random() * 10"), color = spec(1:100, transform = " var rnd = function() { return Math.floor(Math.random() * 255); } return '#' + (rnd()).toString(16) + (rnd()).toString(16) + (rnd()).toString(16); ")) # using spec to specify size of points # requires google API key ## Not run: gmap(lat = 40.44, lng = -113.785, zoom = 4, width = 1000, height = 700, map_style = gmap_style("blue_water"), map_type = "roadmap") %>% ly_points(long, lat, data = us.cities, color = factor(capital), size = spec(pop, range = c(2, 50)), hover = us.cities) ## End(Not run)