ez.countplot: plot count data

View source: R/plot.R

ez.countplotR Documentation

plot count data

Description

plot count data, eg, ez.countplot(iris, 'Species'). See also ez.piechart ez.hist

Usage

ez.countplot(
  df,
  cmd,
  position = "both",
  color = "color",
  colors = ez.palette("Zhu"),
  alpha = 1,
  title.size = 20,
  n.size = 5.5,
  n.angle = 0,
  n.type = 3,
  width = 0.7,
  ylab = NULL,
  xlab = NULL,
  zlab = NULL,
  legend.position = "top",
  legend.direction = "horizontal",
  legend.box = T,
  legend.size = c(0, 10),
  facet = "cols",
  theme.apa = TRUE
)

Arguments

df

data frame in long format (but be careful that standard error might be inaccurate depending on grouping in the long format)
if it is already summary data, use mutate(tidyr::uncount(counter), value = 1) to turn into long format

cmd

like "x", c("x1", "x2", "x3"), "x|z", "x|z a" where x z a are all discrete.

position

so far can only be "stack", "fill", "both". ('dodge' not supported yet)

color

"bw" or "color" black/white or colorblind-friendly color

alpha

bar alpha value

n.size

set to 0 to hide count/percentage

n.angle

0, 45, 90, 180, 270

n.type

1 = n for stack, pct for fill; 2 = pct for stack, n for fill; 3 = n (pct) for stack, pct (n) for fill; 4 = pct (n) for stack, n (pct) for fill

width

the width of bar/bin itself

ylab

y label NULL

xlab

x label NULL

zlab

z/a/fill/legend label, only applicable when there is z provided NULL

legend.position

legend position 'top', 'bottom', 'left', 'right', 'none', c(x,y,two-element numeric vector)
c(0,0) corresponds to the "bottom left" and c(1,1) corresponds to the "top right" position.
if no z/a (legend) provided, auto force to 'none'

legend.direction

horizontal or vertical

legend.box

box of legend, T or F

legend.size

c(0,10) the first number 0 controls the legend title, 0=hide; the second number controls legend.key.size, legend.text

facet

one of 'cols', 'rows', 'wrap'

Value

a ggplot object (+theme_apa() to get apa format plot), +scale_y_continuous(limits=c(-5,8),breaks=seq(-5,8,by=2),oob=scales::rescale_none), +theme(axis.text.y = element_blank(), axis.ticks.y = element_blank())
see http://stackoverflow.com/a/31437048/2292993 for discussion


jerryzhujian9/ezmisc documentation built on March 9, 2024, 12:44 a.m.