You're welcome, and just to follow up on gather(): The tidyr package is a subpackage of the tidyverse package, which also includes ggplot2 as a subpackage, so if you'd like everything at once, you can use library(tidyverse) to load them all. Also, gather() is older version of the more current pivot_longer() command, so I thought I'd include a version of @raytong's code that uses it, instead, too:
library(tidyverse)
library(RColorBrewer)
liwc_Nachname <- tibble::tribble(
~Nachname, ~Tentative, ~Certain, ~Ratio,
"abc", 195, 516, 321,
"def", 140, 483, 343,
"dgh", 92, 512, 420,
"dfh", 56, 262, 206,
"zit", 93, 368, 275,
"fxg", 67, 464, 397,
"awr", 143, 582, 439,
"nvg", 98, 448, 350,
"uipi", 209, 666, 457,
"lzu", 155, 487, 332,
"awe", 115, 398, 283,
"sdg", 222, 670, 448,
"cvb", 124, 539, 415,
"mjk", 158, 406, 248)
nb.cols = 14
mycolors = colorRampPalette(brewer.pal(8, "Set2"))(nb.cols)
liwc_Nachname %>%
# convert Nachname to factor, with levels according to 'Ratio' values
mutate(Nachname = reorder(Nachname, Ratio)) %>%
# reshape table by placing the column names 'Tentative', 'Certain, and
# 'Ratio' in their own column, called 'numeric_vars', and place the
# corresponding values in a new column, called 'numeric_values'
pivot_longer(
cols = -Nachname, # collect column names of all but Nachname
names_to = 'numeric_columns', # where to place them
values_to = 'numeric_values', # for corresponding values
)
# more abbreviated version that uses defaults
liwc_Nachname %>%
mutate(Nachname = reorder(Nachname, Ratio)) %>%
pivot_longer(-Nachname) # place names in 'name', their values in 'value'
# plot
liwc_Nachname %>%
mutate(Nachname = reorder(Nachname, Ratio)) %>%
pivot_longer(-1) %>% # exclude 'Nachname' by column index
ggplot() +
geom_col(aes(Nachname, value, fill = name), position = "dodge") +
scale_fill_manual(values = mycolors)