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.
devtools::install_github("JohnCoene/peity")
library(peity)
peity("1/5", type = "pie")
# pass options as list
peity(c(1,5), type = "donut", options = list(fill = I(c("green", "red")), radius = 100))
peity(c(1,5), type = "donut", options = list(fill = c("#845422", "#ead61c"), radius = 50, innerRadius = 40))
peity(rnorm(50, 2, 1), type = "line", options = list(width = 100))
peity(c(1,5,3), type = "bar", options = list(fill = I("green")))
peity(c(4,-2,3, -4), type = "bar", options = list(fill = htmlwidgets::JS('function(value) {
return value > 0 ? "green" : "red"
}')))
js_fun <- htmlwidgets::JS('function(_, i, all) {
var g = parseInt((i / all.length) * 255)
return "rgb(255, " + g + ", 0)"
}')
peity(c(0,-3,-6,-4,-5,-4,-7,-3,-5,-2), type = "bar", options = list(fill = js_fun))
Use in rmarkdown in-line like so r peity(c(1,4,2), type = "pie")
, or in blocks like so:
peity(c(1,4,2), type = "pie")