Making the conversion on the data is trivial, the challenge would be to get a primary y-axis with frequency and a secondary y-axis with percentages, I don't know how to do it or if it's possible with ggplot2, I think you can do it with base R and lattice but I don't remember how.
library(tidyverse)
df <- data.frame(
First_response = c(201L, 8L, 107L, 151L, 282L),
Second_response = c(72L, 17L, 148L, 225L, 260L),
Third_response = c(54L, 17L, 177L, 220L, 360L),
Fourth_response = c(46L, 24L, 168L, 198L, 356L),
Fifth_response = c(39L, 13L, 122L, 150L, 402L),
Frequency = c(749L, 722L, 828L, 792L, 726L),
modality = as.factor(c("Appearance",
"Aroma","Flavor","Texture","Hedonic"))
)
df %>%
mutate_at(vars(-modality, - Frequency), ~ . / Frequency) %>%
gather(Response, Percentage, First_response:Fifth_response) %>%
mutate(Response = factor(Response,
levels = c("First_response", "Second_response",
"Third_response", "Fourth_response",
"Fifth_response"))) %>%
ggplot(aes(x = Response, y = Percentage, fill = modality)) +
geom_col(position = "dodge") +
geom_text(aes(label = scales::percent(Percentage,
accuracy = 0.1)),
position = position_dodge(width=0.9),
vjust = -0.25) +
labs(x = NULL, y = "Percentage") +
scale_y_continuous(labels = scales::label_percent()) +
scale_fill_brewer('Variables', palette='Spectral') +
theme_bw() +
theme(legend.title = element_blank(),
legend.position = c(.3, .95),
legend.direction = "horizontal")
