I have the following dataset:
df = structure(list(words = c("purchases", "may", "balance", "sheet",
"balance_sheet", "debt", "policy", "last", "risks", "says", "years",
"still", "higher", "eurozone", "strategy_review", "need", "growth",
"germany", "asset", "purchases", "may", "balance", "sheet", "balance_sheet",
"debt", "policy", "last", "risks", "says", "years", "still",
"higher", "eurozone", "strategy_review", "need", "growth", "germany",
"asset"), weeks = c("W1", "W1", "W1", "W1", "W1", "W1", "W1",
"W1", "W1", "W1", "W1", "W1", "W1", "W1", "W1", "W1", "W1", "W1",
"W1", "W2", "W2", "W2", "W2", "W2", "W2", "W2", "W2", "W2", "W2",
"W2", "W2", "W2", "W2", "W2", "W2", "W2", "W2", "W2"), frequency = c(0.12962962962963,
0.0555555555555556, 0.037037037037037, 0.037037037037037, 0.037037037037037,
0.0185185185185185, 0, 0.0740740740740741, 0.0185185185185185,
0.0740740740740741, 0, 0.037037037037037, 0.0555555555555556,
0.0185185185185185, 0, 0, 0.0555555555555556, 0.037037037037037,
0.0185185185185185, 0.0657894736842105, 0.0263157894736842, 0.0263157894736842,
0.0263157894736842, 0.0263157894736842, 0, 0.0526315789473684,
0.0789473684210526, 0.0131578947368421, 0.0921052631578947, 0.0394736842105263,
0.0263157894736842, 0.0131578947368421, 0.0263157894736842, 0.0394736842105263,
0.0263157894736842, 0.0526315789473684, 0.0263157894736842, 0
)), row.names = c(NA, 38L), class = "data.frame")
At the moment I am plotting it in this way:
df %>%
ggplot(aes(x = weeks, y = frequency, group=1)) +
geom_line() +
facet_wrap(~ words, scales = "free") +
labs(x = NULL, y = "Relative frequency")
The well-know issue with this is that facet_wrap
plots the labels alphabetically. Instead, I would like to plot it on the basis of the highest frequency of the latest week (second week in this case, W2).
Is there anyone who could help me achieve it?
Thanks!