dotplot: dotplot

View source: R/plot2.R

dotplotR Documentation

dotplot

Description

Draw a dotplot.

Usage

dotplot(
  x,
  at = NULL,
  names = rownames(x),
  label = TRUE,
  col = NULL,
  col.rect = "grey95",
  radius = 0.25,
  width = radius * 2,
  horiz = TRUE,
  axes = TRUE,
  xlim = NULL,
  ylim = NULL,
  reset_par = TRUE,
  ...
)

Arguments

x

an r x 3 numeric matrix

at

a numeric vector giving the locations where each row is drawn

names

optional axis labels for each row

label

logical; if TRUE, each dot is labeled with its numeric value

col, col.rect

vectors of colors for dots and background shading

radius, width

numeric values controlling the size of dots and background shading

horiz

logical; if TRUE (default), dots are plotted horizontally

axes

logical; if TRUE, an x- or y-axis is drawn if horiz is TRUE or FALSE, respectively

xlim, ylim

the x- and y-axis limits

reset_par

logical; if TRUE (default), graphical parameters are reset to state before function call

...

additional graphical parameters passed to par

Examples

# https://twitter.com/RandyRenstrom/status/1318053323828756480/photo/1
x <- c(
  39, 55, 36, 47, 32, 58, 57, 17, 14, 17, 43, 49, 40, 38, 28,
  60, 57, 56, 52, 49, 46, 45, 43, 43, 42, 40, 36, 36, 33, 23,
  85, 68, 73, 58, 69, 48, 43, 68, 64, 62, 44, 35, 31, 36, 19
)
y <- c(
  'The coronavirus pandemic',
  'Fairness of presidential elections',
  'Health care',
  'Jobs and employment',
  'Foreign interference in presidential elections',
  'Crime',
  'Terrorism',
  'Racial inequality',
  'Climate change',
  'Growing gap between rich and poor',
  'Appointment of U.S. Supreme Court Justices',
  'Abortion',
  'The federal deficit',
  'Immigration',
  'Trade agreements with other countries'
)
x <- matrix(x, ncol = 3L, dimnames = list(y, c('R', 'All', 'D')))

dotplot(x, col = c('blue4', 'darkgrey', 'tomato2'))

col <- rep_len('grey96', nrow(x))
col[which.max(apply(x[, -2], 1, diff))] <- 'darkgrey'
dotplot(x, col.rect = col)


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.