Skip to content

Instantly share code, notes, and snippets.

View reorder_factors.r
# example ordering of elements in a factor for use in a graph:
mock <- data.frame(
element = as.factor(c(rep("foo", 10), rep("bar", 10), rep("hello", 10))),
value = rnorm(30))
levels(mock$element)
# [1] "bar" "foo" "hello"
# defining custom order for the elements:
my_order <- as.character(c("hello", "foo", "bar"))