But we specified color with a single argument color. In the example above, the points in our plot have both line attributes (the outline of the circles) and fill attributes (the area inside the circles). Which of these categories a glyph falls into is usually evident from the name of the layer function and is spelled out in the function reference. We can build on the object p that we initialized above:Įvery layer function has either line attributes or line and fill attributes (except for ly_text(), which has text attributes). All layer functions return a figure object, which can be passed to further layer functions.įor example, suppose we would like to plot the distance to stop vs. speed from the cars data. Following this, most layer functions take as next arguments x and y to specify the x and y location of the placement of the glyphs, followed by several arguments for specifying attributes of the glyphs. The first argument of a layer function is always the figure to be modified. All layer functions conveniently start with the ly_ prefix, and a full list can be found in the function reference. We can add a layer to the figure by calling a number of layer functions. We now have a figure object, p, which we are ready to add layers to. There are several arguments to figure() which control things like the width, height, and axes of the figure. This is a familiar notion to those who have experience with ggplot2 geoms, ggvis layers, or even base R graphics functions points(), lines(), etc. Plots in rbokeh are build by layering plot elements, called glyphs, to create the desired visualization. Ylab = "Vertical distance from home plate (ft.)") %>% ly_baseball() %>% ly_hexbin( doubles, xbins = 50, shape = 0.77, alpha = 0.75, palette = "Spectral10") Xlab = "Horizontal distance from home plate (ft.)", Hover = list( name, atomic.number, type, atomic.mass,Įnfiguration)) %>% # add symbol text ly_text( symx, period, text = symbol, data = elements,Īlign = "left", baseline = "middle") %>% # add atomic number text ly_text( symx, numbery, text = atomic.number, data = elements,įont_size = "6pt", align = "left", baseline = "middle") %>% # add name text ly_text( symx, namey, text = name, data = elements,įont_size = "4pt", align = "left", baseline = "middle") %>% # add atomic mass text ly_text( symx, massy, text = atomic.mass, data = elements,įont_size = "4pt", align = "left", baseline = "middle")ĭoubles % # boundary ly_segments( c( 0, 0), c( 0, 0), c(- 300, 300), c( 300, 300), alpha = 0.4) %>% # bases ly_crect( base_x, base_y, width = 10, height = 10,Īngle = 45* pi/ 180, color = "black", alpha = 0.4) %>% # infield/outfield boundary ly_curve( 60.5 + sqrt( 95^ 2 - x^ 2),įrom = base_x - 26, to = base_x + 26, alpha = 0.4) %>% # distance arcs (ly_arc should work here and would be much simpler but doesn't) ly_multi_line( distarc_x, distarc_y, alpha = 0.4)įigure( xgrid = FALSE, ygrid = FALSE, width = 630, height = 540, # prepare data elements % # plot rectangles ly_crect( group, period, data = elements, 0.9, 0.9,įill_color = color, line_color = color, fill_alpha = 0.6,
0 Comments
Leave a Reply. |