dotplot | R Documentation |
Draw a dotplot.
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,
...
)
x |
an |
at |
a numeric vector giving the locations where each row is drawn |
names |
optional axis labels for each row |
label |
logical; if |
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 |
axes |
logical; if |
xlim, ylim |
the x- and y-axis limits |
reset_par |
logical; if |
... |
additional graphical parameters passed to |
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.