I currently want to display different metrics obtained from running some experiments using different models, methods and corpora. What I have so far is after I followed this.
My problem is now: how can I group the 3 metrics for each method so that they touch each other while having a gap between each method group? How can I get the proper labels back, maybe O, P, R under each and then below each group the method name (or a better way)?
In reality, I have many more observations, that is why I try to find a compact way to display all of them space-efficiently. Suggestions for a different visualizations are also welcome.
library(tidyverse)
library(ggplot2)
library(patchwork)
set.seed(15)
models <- c("Model1", "Model2")
methods <- c("Method1", "Method2")
corpora <- c("Corpus1", "Corpus2")
n <- length(models) * length(methods) * length(corpora)
df <- expand.grid(model = models, method= methods, corpus =corpora) %>%
add_column(
overall = runif(n = n, min = 0, max = .8),
precision = runif(n = n, min = 0, max = .8),
recall = runif(n = n, min = 0, max = .8),
)
# Model1 Method1 Corpus1 0,481691 0,549785 0,357955
# Model2 Method1 Corpus1 0,156035 0,665143 0,771734
# Model1 Method2 Corpus1 0,773167 0,0837355 0,112950
# Model2 Method2 Corpus1 0,520724 0,516921 0,621370
# Model1 Method1 Corpus2 0,293658 0,407272 0,642982
# Model2 Method1 Corpus2 0,791087 0,565303 0,634677
# Model1 Method2 Corpus2 0,652155 0,689851 0,286050
# Model2 Method2 Corpus2 0,203175 0,673428 0,0464008
I started with a simple barchart:
plot_with_one_metric <- df %>%
arrange(-overall) %>%
ggplot(aes(fill=model, y=overall, x=method)) +
geom_col( position = "identity") +
facet_grid(~ corpus)
And then I extended it to several metrics, this is the plot I want am stuck on. I do not know how I could alter the labels in code and group metric bars so that they have no gaps.
plot_with_several_metrics <- df %>%
pivot_longer(c("overall", "precision", "recall"), names_to = "metric", values_to = "value") %>%
arrange(-value) %>%
ggplot(aes(x = interaction(method, metric, lex.order=TRUE), y = value, fill = model)) +
geom_col(position = "identity") +
theme(axis.text.x = element_text(angle = 90)) +
facet_grid(~ corpus)
plot_with_one_metric / plot_with_several_metrics