Skip to content

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

Open
@awunderground

Description

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")

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions