Skip to content

Instantly share code, notes, and snippets.

@padpadpadpad
Created February 5, 2018 16:08
Show Gist options
  • Save padpadpadpad/6b577408470381feaae6348889433187 to your computer and use it in GitHub Desktop.
Save padpadpadpad/6b577408470381feaae6348889433187 to your computer and use it in GitHub Desktop.
library(ggplot2)
d <- data.frame(x = rnorm(20), y = rnorm(20))
d$row <- paste('C', row.names(d), sep = '_')
# random plot
ggplot(d, aes(row, y)) +
geom_point()
# order by y, highest first
ggplot(d, aes(forcats::fct_reorder(row, y, .desc = TRUE), y)) +
geom_point()
# order by y, lowest first
ggplot(d, aes(forcats::fct_reorder(row, y), y)) +
geom_point()
# order by x
ggplot(d, aes(forcats::fct_reorder(row, x), y)) +
geom_point()
@AmirulLearn
Copy link

Hey,can i have your permission to run your coding on my pc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment