-
-
Save timelyportfolio/60c9676395f541d1d743 to your computer and use it in GitHub Desktop.
more rbokeh examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#devtools::install() | |
library(rbokeh) | |
p1 <- figure( height = 300, width = 300) %>% | |
ly_points(Sepal.Length, Sepal.Width, data = iris, | |
color = Species, glyph = Species, | |
hover = list(Sepal.Length, Sepal.Width)) | |
z <- lm(dist ~ speed, data = cars) | |
p2 <- figure(width = 300, height = 300) %>% | |
ly_points(cars, hover = cars) %>% | |
ly_lines(lowess(cars), legend = "lowess") %>% | |
ly_abline(z, type = 2, legend = "lm") | |
p1 | |
p2 | |
# compose a page of bokehs | |
library(htmltools) | |
html_print( | |
tagList( | |
rbokeh:::plot.BokehFigure(p1) | |
,rbokeh:::plot.BokehFigure(p2) | |
) | |
) | |
# compose bokehs with other tags and widgets | |
library(DiagrammeR) | |
html_print( | |
tagList( | |
tags$h1(style="font-size:300%;","Fun with htmlwidgets") | |
,tags$hr() | |
,tags$div( | |
style="float:left;border-style:solid;border-color:gray;" | |
,mermaid("graph LR; rbokeh-->|is|awesome;",height=200,width=200) | |
) | |
,tags$div( | |
style="float:left;border-style:solid;border-color:gray;" | |
,rbokeh:::plot.BokehFigure(p1) | |
) | |
,tags$div( | |
style="float:left;border-style:solid;border-color:gray;" | |
,rbokeh:::plot.BokehFigure(p2) | |
) | |
) | |
,viewer = utils::browseURL | |
) | |
# correlation plot with ly_text using cor example | |
(Cl <- cor(longley)) | |
# convert to long format with tidyr::gather | |
Cl_long <- tidyr::gather( data.frame(x = rownames(Cl),Cl), y, correlation, -x ) | |
Cl_long[,1:2] <- lapply(Cl_long[,1:2],as.character) | |
# build our plot | |
(p <- figure( | |
title = "Correlation Plot" | |
,ylim = unique(Cl_long$indicator) | |
,xlim = unique(Cl_long$indicator) | |
,xgrid = FALSE | |
,ygrid = FALSE | |
,height = 700 | |
,width = 700 | |
,tools = c("resize","hover") | |
) %>% | |
ly_points( x, y, data = Cl_long, glyph=15, size = correlation, color = correlation, hover = list(x,y) ) | |
) | |
# but this doesn't work | |
p %>% ly_crect( x, y, data = Cl_long, color = correlation ) | |
# similar to http://bokeh.pydata.org/en/latest/tutorial/advanced.html | |
data("MisLinks",package="networkD3") | |
data("MisNodes",package="networkD3") | |
p <- figure( | |
xlim = as.character(sort(1:max(MisLinks$source))) | |
,ylim = as.character(sort(1:max(MisLinks$target))) | |
,xlab = "source" | |
,ylab = "target" | |
,height = 800 | |
,width = 800 | |
) | |
p %>% | |
ly_points( | |
as.character(source), as.character(target), MisLinks, size = 3, color = value | |
) %>% | |
# thanks @hafen for showing me the new fine-grained axis control | |
x_axis(major_label_text_font_size = "6pt", major_label_orientation = 90) %>% | |
y_axis(major_label_text_font_size = "6pt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lot of these examples are generating "object 'plot.BokehFigure' not found" errors using the dev branch of rbokeh