| sort_gg | R Documentation | 
Helper function to sort categories for display in ggplot, for ensuring that column charts are ordered by magnitude
sort_gg(df_gathered, group_by_column, sort_by, filter_scenario = "Last3M")
df_gathered | 
 long form dataframe (see tidyr::gather) for plotting  | 
group_by_column | 
 name of column to group by  | 
sort_by | 
 name of column to sort by  | 
filter_scenario | 
 filters data to the required scenario, defaults to 'Last3M'  | 
dataframe but with category levels sorted
library(ggplot2)
input_text <- "period asset_class active_risk\n
      Last3M Equity 1.256309e-05\n
      Last3M Fixed_Income 1.389163e-03\n
      Last3M FX 1.531547e-04\n
      Last3M Others 2.138171e-05\n
      GFCStress Equity 2.083595e-04\n
      GFCStress Fixed_Income 4.309154e-03\n
      GFCStress FX 9.310046e-04\n
      GFCStress Others 2.353732e-04\n
      TaperTantrum Equity 2.892491e-05\n
      TaperTantrum Fixed_Income 2.097302e-03\n
      TaperTantrum FX 1.601432e-04\n
      TaperTantrum Others 6.576230e-05"
input_table <- read.table(text=input_text, header = 1)
dat <- sort_gg(input_table, "asset_class", "active_risk")
ggplot(dat, aes(x = asset_class, y = active_risk * 10000)) +
  geom_col() +
  facet_wrap(~period, ncol = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.