Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forcats::fct_reorder() for the dot plot #31

Open
awunderground opened this issue Dec 18, 2018 · 0 comments
Open

forcats::fct_reorder() for the dot plot #31

awunderground opened this issue Dec 18, 2018 · 0 comments
Assignees
Labels
beginner-friendly Good for newcomers feature New feature or request

Comments

@awunderground
Copy link
Collaborator

Use forcats::fct_reorder() to reorder the data instead of the messy mutate. This is under dot plot/cleveland dot plot.

mtcars %>%
  rownames_to_column("model") %>%
  arrange(mpg) %>%
  mutate(model = factor(model, levels = .$model)) %>%
  ggplot(aes(mpg, model)) +
    geom_segment(aes(x = 0, xend = mpg, y = model, yend = model)) + 
    geom_point() +
    scale_x_continuous(expand = expand_scale(mult = c(0, 0)), limits = c(0, 40)) +
    labs(x = NULL, 
         y = "Miles Per Gallon")
@awunderground awunderground added feature New feature or request beginner-friendly Good for newcomers labels Dec 18, 2018
@awunderground awunderground self-assigned this Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner-friendly Good for newcomers feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant