Skip to content

Instantly share code, notes, and snippets.

@mollietaylor
Created November 13, 2012 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mollietaylor/4063837 to your computer and use it in GitHub Desktop.
Save mollietaylor/4063837 to your computer and use it in GitHub Desktop.
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