R/piechart.R

Defines functions piechart

Documented in piechart

piechart <- function(x, scale=c("percent", "frequency", "none"), 
                     col=rainbow_hcl(nlevels(x)), ...){
  scale <- match.arg(scale)
  if (!is.factor(x)) x <- as.factor(x)
  labels <- levels(x)
  tab <- table(x)
  labels <- if (scale == "percent") {
    tab <- 100*tab/sum(tab)
    paste0(labels, " (", round(tab), "%)")
  } else if (scale == "frequency") paste0(labels, " (", tab, ")")
    else labels
  pie(tab, labels=labels, col=col, ...)
}

Try the RcmdrMisc package in your browser

Any scripts or data that you put into this service are public.

RcmdrMisc documentation built on Aug. 13, 2020, 9:06 a.m.