Skip to content

htmlwidgets/morris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Morris

This is an experimental R package that provides the Morris visualization library as a html widget for R. The implementation in this package borrows heavily from some utility functions in rCharts, but uses the htmlwidgets package to deliver the widget.

Installation

You can install it from github

pkgs <- c('rstudio/htmltools', 'ramnathv/htmlwidgets', 'ramnathv/morris')
devtools::install_github(pkgs)

Usage

Here are some simple examples that you can play with.

Line Chart

dat = data.frame(
  year = as.character(2008:2012),
  value = c(20, 10, 5, 5, 20)
)
morris(value ~ year, data = dat, type = 'Line')

morris1

Bar Chart

haireye = as.data.frame(HairEyeColor)
dat <- subset(haireye, Sex == "Female" & Eye == "Blue")
morris(Freq ~ Hair, data = dat, type = 'Bar', labels = list("Count"))

morris2

MultiBar Chart

haireye = as.data.frame(HairEyeColor)
dat = subset(haireye, Sex == "Female")

morris(Freq ~ Eye, 
  group = "Hair", 
  data = dat, 
  type = "Bar", 
  labels = levels(dat$Hair),
  barColors = c('black', 'brown', 'red', '#FAF0BE')  
)

morris3

You can also use it in a Shiny app

library(shiny)
library(htmlwidgets)
library(morris)

dat = data.frame(
  year = as.character(2008:2012),
  value = c(20, 10, 5, 5, 20)
)

ui = bootstrapPage(
  selectInput('type', 'Choose Type', c('Line', 'Bar')),
  textInput('units', 'Choose', 'Km'),
  morrisOutput('myplot', 600, 400)
)

server = function(input, output, session){
  output$myplot <- renderWidget({
    morris(value ~ year, data = dat, type = input$type, labels = list("Value"),
      yLabelFormat = sprintf("function(y){return y.toString() + ' %s'}", 
        input$units)       
    )
  })
}

runApp(list(ui = ui, server = server))

About

Morris JS HTML Widget for R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages