View source: R/plot_order_set.R
plot_order_set | R Documentation |
Sets order for a ggplot using a column and a vector
plot_order_set(df, Column, Order)
df |
tidy data frame to be ordered |
Column |
which column to be ordered. |
Order |
Vector to order by. |
Orders ggplot
library(tidyverse);library(lubridate)
dfplot <- fmxdat::SectorTRIs %>% gather(type, val, -Date)
ord <- rev(unique(dfplot$type))
dfplot %>% ggplot() + geom_line(aes(Date, val, color = type))
# Reordered now:
dfplot %>% plot_order_set( Column = "type", Order = ord) %>% ggplot() + geom_line(aes(Date, val, color = type))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.