Skip to content

Instantly share code, notes, and snippets.

@mollietaylor
Created Nov 13, 2012
Embed
What would you like to do?
Sorting Within Lattice Graphics in R
library(lattice)
colors = c("#1B9E77", "#D95F02", "#7570B3")
dotplot(rownames(mtcars) ~ mpg,
data = mtcars,
col = colors[1],
pch = 1)
dotplot(reorder(rownames(mtcars), cyl) ~ mpg,
data = mtcars,
col = colors[1],
pch = 1)
dotplot(reorder(rownames(mtcars), cyl) ~ mpg + cyl,
data = mtcars,
col = colors,
pch = c(1, 0))
dotplot(reorder(rownames(mtcars), -cyl) ~ mpg + cyl,
data = mtcars,
col = colors,
pch = c(1, 0))
dotplot(reorder(rownames(mtcars), -cyl) ~ mpg + cyl,
data = mtcars,
xlab = "",
col = colors,
pch = c(1, 0),
key = list(points = list(col = colors[1:2], pch = c(1, 0)),
text = list(c("Miles per gallon", "Number of cylinders")),
space = "bottom"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment