could not find function "fct_reorder"

> p <- min_var %>%
+   gather(MSFT:RTN.L, key = Asset,
+          value = Weights) %>%
+   mutate(Asset = as.factor(Asset)) %>%
+   ggplot(aes(x = fct_reorder(Asset,Weights), y = Weights, fill = Asset)) +
+   geom_bar(stat = 'identity') +
+   theme_minimal() +
+   labs(x = 'Assets', y = 'Weights', title = "Minimum Variance Portfolio Weights") +
+   scale_y_continuous(labels = scales::percent) 
> 
> ggplotly(p)

Error in fct_reorder(Asset, Weights) : 
  could not find function "fct_reorder"

^ Can somebody help? Not sure where to go from here. Thank you.

That function comes frome the forcats package so you have to load it first (assuming you alredy have it installed).

library(forcats)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.