To convey the relative frequencies of key words, I would like each "bar" in a plot to consist of one of the words repeated vertically by its frequency. The ggplot
code below removes the outline of the bar and the fill, but how can I create a "stack" of words as (or in) a bar according to the word's frequency? Thus "global" would start at the x-axis and repeat "global" three times vertically, position against 1, 2, and 3 of the y-axis; "local" would stack five times, etc.
# a toy data frame
words <- c("global", "local", "firm")
freq <- c(3, 5, 6)
df <-data.frame(cbind(words, freq))
library("ggthemes")
# a very unimpressive and uninformative plot
ggplot(df, aes(x = words, y = freq)) +
geom_bar(stat = "identity", fill = "transparent", colour = "white") +
theme_tufte()
I tried to use annotation_custom()
with a textGrob but couldn't figure out how to repeat the word by its frequency.
Thank you for any guidance.