⚠️ Work in progress ⚠️
The goal of hierplane
is to visualize trees. This is an HTML widget that uses source code from the original javascript library. A handful of functions are provided that allow R users to render hierplanes in shiny. See a live demonstration here.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("r4fun/hierplane")
Rendering a hierplane requires you to:
hp_
functionshierplane()
A hierplane object can be created from different input data, below are some examples:
library(hierplane) # from a string, requires spacyr package hp_spacyr("Sam likes boats") #> <hierplane_tree object> # from a dataframe hp_dataframe(starships) #> <hierplane_tree object> # from YAML, requires data.tree and yaml package yaml <- " name: r4fun tyler: name: Tyler job: Data Scientist species: Human "aml x <- data.tree::as.Node(yaml::yaml.load(yaml)) hp_datatree(x) #> <hierplane_tree object>
With this, we can render a hierplane in shiny:
library(hierplane) library(shiny) ui <- fluidPage( hierplaneOutput("hplane") ) server <- function(input, output, session) { output$hplane <- renderHierplane({ x <- hp_spacyr("Sam likes boats") hierplane(x) }) } shinyApp(ui, server)
If you are familiar with data.tree
, you can use it to visualize trees as well. Here is an example of generating a hierplane from YAML:
library(data.tree) library(yaml) " name: r4fun tyler: name: Tyler job: Data Scientist species: Human toulouse: name: Toulouse job: Systems Engineer species: Cat jojo: name: Jojo job: Python Programmer species: Dog ollie: name: Ollie job: Database Administrator species: Dog lucas: name: Lucas job: R Programmer species: Rabbit " name: r4fun tyler: name: Tyler job: Data Scientist species: Human toulouse: name: Toulouse job: Systems Engineer species: Cat jojo: name: Jojo job: Python Programmer species: Dog ollie: name: Ollie job: Database Administrator species: Dog lucas: name: Lucas job: R Programmer species: Rabbit " -> yaml yaml %>% yaml.load() %>% as.Node() %>% hp_datatree( title = "r4fun github group", link = "species", attributes = "job" ) %>% hierplane( theme = "light", width = "auto", height = "auto" )
While hierarchical data isn’t common in a data.frame
centric language like R, we are working on a way to parse a data.frame
to hierplane ready data. This works by using hp_dataframe()
:
ui <- fluidPage( hierplaneOutput("hplane") ) server <- function(input, output, session) { output$hplane <- renderHierplane({ hierplane(hp_dataframe(starships, title = "Starships")) }) } shinyApp(ui, server)
allenai/hierplane
: The original javascript library that this package usesDeNeutoy/spacy-vis
: Spacy models using hierplane