Last active
August 3, 2017 21:09
-
-
Save thoolihan/821f5d88210ac3a271cf75c0fbd38fec to your computer and use it in GitHub Desktop.
arrange and plot not working together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
mtcars %>% | |
mutate(car = rownames(.)) %>% | |
arrange(hp) %>% | |
ggplot(aes(x = car, y = hp)) + | |
geom_point() + | |
theme(axis.text.x = element_text(angle = 45, hjust = 1)) | |
# should be | |
# see https://stackoverflow.com/questions/20041136/avoid-ggplot-sorting-the-x-axis-while-plotting-geom-bar | |
mtcars %>% | |
arrange(hp) %>% | |
mutate(car = factor(rownames(.), levels = rownames(.))) %>% | |
ggplot(aes(x = car, y = hp, color = factor(cyl))) + | |
geom_point() + | |
theme(axis.text.x = element_text(angle = 45, hjust = 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment