res = pca_res$Y %>% rescale(to=c(-1, 1)) %>% as_tibble()
res$word = deduped_words$word
res %>%
pivot_longer(!word, names_prefix="V", names_to="pca", names_transform =list(pca=as.integer)) %>%
group_by(pca) %>%
top_n(12, abs(value)) %>%
ungroup() %>%
mutate(word = reorder_within(word, value, pca)) %>%
ggplot(aes(word, value, fill=pca)) +
geom_col(alpha=0.8, show.legend = FALSE) +
facet_wrap(~pca, scales = "free_y", ncol = 4) +
scale_x_reordered() +
coord_flip() +
labs(
x = NULL,
y = "Value"
)
```
```{r}
g2 <- res[1:200,] %>% ggplot(aes(x=V1, y=V2, label=word)) + geom_text(aes(label=word), hjust=0, vjust=0, color="blue")
ggplotly(g2, tooltip = 'word')
```