项目作者: JohnCoene

项目描述 :
Inline charts for R
高级语言: R
项目地址: git://github.com/JohnCoene/peity.git
创建时间: 2017-02-14T11:31:52Z
项目社区:https://github.com/JohnCoene/peity

开源协议:Other

下载


Build Status
saythanks

peity

Peity htmlwidget for R.

Peity (sounds like deity) is a jQuery plugin that converts an element’s content into a mini pie donut line or bar chart and is compatible with any browser that supports : Chrome, Firefox, IE9+, Opera, Safari.

Install

  1. devtools::install_github("JohnCoene/peity")

Basics

  1. library(peity)
  2. peity("1/5", type = "pie")
  3. # pass options as list
  4. peity(c(1,5), type = "donut", options = list(fill = I(c("green", "red")), radius = 100))
  5. peity(c(1,5), type = "donut", options = list(fill = c("#845422", "#ead61c"), radius = 50, innerRadius = 40))
  6. peity(rnorm(50, 2, 1), type = "line", options = list(width = 100))
  7. peity(c(1,5,3), type = "bar", options = list(fill = I("green")))

Set colors dynamically

  1. peity(c(4,-2,3, -4), type = "bar", options = list(fill = htmlwidgets::JS('function(value) {
  2. return value > 0 ? "green" : "red"
  3. }')))
  4. js_fun <- htmlwidgets::JS('function(_, i, all) {
  5. var g = parseInt((i / all.length) * 255)
  6. return "rgb(255, " + g + ", 0)"
  7. }')
  8. peity(c(0,-3,-6,-4,-5,-4,-7,-3,-5,-2), type = "bar", options = list(fill = js_fun))

Rmarkdown

Use in rmarkdown in-line like so r peity(c(1,4,2), type = "pie"), or in blocks like so:

  1. peity(c(1,4,2), type = "pie")