Please find here complete code along with actual data:
df <- data.frame(
H1 = c(6.36, 3.03, 6.85, 4.07, 4.69, 6.27, 6.67, 3.11, 5.07, 6.14, 5.93, 6.49),
H2 = c(5.15, 5.00, 5.71, 5.50, 4.99, 5.81, 6.05, 5.76, 5.28, 5.69, 5.69, 5.06),
H3 = c(3.85, 5.13, 4.99, 4.91, 5.01, 5.73, 5.77, 5.94, 5.57, 5.35, 6.00, 4.39),
H4 = c(3.84, 4.80, 5.15, 4.85, 4.99, 5.73, 5.77, 5.45, 5.44, 5.41, 5.81, 4.46),
H5 = c(4.08, 5.17, 4.77, 5.03, 5.00, 5.49, 5.49, 5.80, 5.51, 5.18, 5.76, 4.60),
H6 = c(4.35, 5.59, 5.59, 4.83, 5.52, 5.63, 5.85, 5.74, 5.66, 5.19, 5.79, 4.84),
fontface = c("bold"),
names = c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3",
"Valery", "Rio Colorado", "CO99076-6R", "Purple Majesty",
"AC99330-1P/Y", "CO05068-1RU", "Masquerade", "Canela Russet"),
specie = c(rep("Appearance", 12), rep("Aroma" , 12), rep("Flavor" , 12),
rep("Overall" , 12), rep("Aftertaste", 12), rep("Texture", 12)),
condition = rep(c("Russian Banana", "Vermillion", "Atlantic", "POR12PG28-3",
"Valery", "Rio Colorado", "CO99076-6R", "Purple Majesty",
"AC99330-1P/Y", "CO05068-1RU", "Masquerade",
"Canela Russet") , 6))
df <- df %>%
pivot_longer(starts_with("H"), names_to = "h.names")
#> Error in df %>% pivot_longer(starts_with("H"), names_to = "h.names"): could not find function "%>%"
#one condition per plot
nameframe <- enframe(unique(df$h.names))
#> Error in enframe(unique(df$h.names)): could not find function "enframe"
specieframe <- enframe(unique(df$specie))
#> Error in enframe(unique(df$specie)): could not find function "enframe"
names.labs <- c("Appearance", "Aroma", "Flavor", "Overall",
"Aftertaste", "Texture")
names(names.labs) <- c("H1", "H2", "H3", "H4", "H5", "H6")
#add text onto each bar
df <- df %>%
arrange(desc(names)) %>%
group_by(names) %>%
mutate(
bar_labels = case_when(
(names == "Vermillion" & specie == "Appearance") ~ "e",
(names == "Vermillion" & specie == "Aroma") ~ "d",
(names == "Vermillion" & specie == "Flavor") ~ "bc",
(names == "Vermillion" & specie == "Overall") ~ "bcde",
(names == "Vermillion" & specie == "Aftertaste") ~ "abcd",
(names == "Vermillion" & specie == "Texture") ~ "ab",
(names == "Valery" & specie == "Appearance") ~ "cd",
(names == "Valery" & specie == "Aroma") ~ "d",
(names == "Valery" & specie == "Flavor") ~ "abd",
(names == "Valery" & specie == "Overall") ~ "cde",
(names == "Valery" & specie == "Aftertaste") ~ "bcd",
(names == "Valery" & specie == "Texture") ~ "ab",
(names == "Rio Colorado" & specie == "Appearance") ~ "ab",
(names == "Rio Colorado" & specie == "Aroma") ~ "ab",
(names == "Rio Colorado" & specie == "Flavor") ~ "a",
(names == "Rio Colorado" & specie == "Overall") ~ "abcd",
(names == "Rio Colorado" & specie == "Aftertaste") ~ "abc",
(names == "Rio Colorado" & specie == "Texture") ~ "ab",
(names == "Russian Banana" & specie == "Appearance") ~ "ab",
(names == "Russian Banana" & specie == "Aroma") ~ "bcd",
(names == "Russian Banana" & specie == "Flavor") ~ "d",
(names == "Russian Banana" & specie == "Overall") ~ "f",
(names == "Russian Banana" & specie == "Aftertaste") ~ "e",
(names == "Russian Banana" & specie == "Texture") ~ "c",
(names == "Purple Majesty" & specie == "Appearance") ~ "e",
(names == "Purple Majesty" & specie == "Aroma") ~ "abc",
(names == "Purple Majesty" & specie == "Flavor") ~ "ab",
(names == "Purple Majesty" & specie == "Overall") ~ "ab",
(names == "Purple Majesty" & specie == "Aftertaste") ~ "a",
(names == "Purple Majesty" & specie == "Texture") ~ "a",
(names == "POR12PG28-3" & specie == "Appearance") ~ "d",
(names == "POR12PG28-3" & specie == "Aroma") ~ "abcd",
(names == "POR12PG28-3" & specie == "Flavor") ~ "bc",
(names == "POR12PG28-3" & specie == "Overall") ~ "de",
(names == "POR12PG28-3" & specie == "Aftertaste") ~ "abcd",
(names == "POR12PG28-3" & specie == "Texture") ~ "bc",
(names == "Masquerade" & specie == "Appearance") ~ "b",
(names == "Masquerade" & specie == "Aroma") ~ "abcd",
(names == "Masquerade" & specie == "Flavor") ~ "a",
(names == "Masquerade" & specie == "Overall") ~ "a",
(names == "Masquerade" & specie == "Aftertaste") ~ "ab",
(names == "Masquerade" & specie == "Texture") ~ "a",
(names == "CO99076-6R" & specie == "Appearance") ~ "ab",
(names == "CO99076-6R" & specie == "Aroma") ~ "a",
(names == "CO99076-6R" & specie == "Flavor") ~ "a",
(names == "CO99076-6R" & specie == "Overall") ~ "abc",
(names == "CO99076-6R" & specie == "Aftertaste") ~ "abc",
(names == "CO99076-6R" & specie == "Texture") ~ "a",
(names == "CO05068-1RU" & specie == "Appearance") ~ "ab",
(names == "CO05068-1RU" & specie == "Aroma") ~ "abcd",
(names == "CO05068-1RU" & specie == "Flavor") ~ "ab",
(names == "CO05068-1RU" & specie == "Overall") ~ "abcd",
(names == "CO05068-1RU" & specie == "Aftertaste") ~ "abcd",
(names == "CO05068-1RU" & specie == "Texture") ~ "abc",
(names == "Canela Russet" & specie == "Appearance") ~ "ab",
(names == "Canela Russet" & specie == "Aroma") ~ "cd",
(names == "Canela Russet" & specie == "Flavor") ~ "cd",
(names == "Canela Russet" & specie == "Overall") ~ "ef",
(names == "Canela Russet" & specie == "Aftertaste") ~ "de",
(names == "Canela Russet" & specie == "Texture") ~ "bc",
(names == "Atlantic" & specie == "Appearance") ~ "a",
(names == "Atlantic" & specie == "Aroma") ~ "abc",
(names == "Atlantic" & specie == "Flavor") ~ "abc",
(names == "Atlantic" & specie == "Overall") ~ "cde",
(names == "Atlantic" & specie == "Aftertaste") ~ "cde",
(names == "Atlantic" & specie == "Texture") ~ "ab",
(names == "AC99330-1P/Y" & specie == "Appearance") ~ "c",
(names == "AC99330-1P/Y" & specie == "Aroma") ~ "bcd",
(names == "AC99330-1P/Y" & specie == "Flavor") ~ "ab",
(names == "AC99330-1P/Y" & specie == "Overall") ~ "abcd",
(names == "AC99330-1P/Y" & specie == "Aftertaste") ~ "abc",
(names == "AC99330-1P/Y" & specie == "Texture") ~ "ab",
TRUE ~ as.character(NA)
))
#> Error in df %>% arrange(desc(names)) %>% group_by(names) %>% mutate(bar_labels = case_when((names == : could not find function "%>%"
#plot
ggplot(data = df, mapping = aes(x = names, y = value)) +
geom_col(position = "dodge") +
coord_flip() +
ylim(c(0,9)) +
scale_y_continuous(breaks=seq(0.0, 9, 3), limits=c(0, 9),
labels = c("0", "3", "6", "Like\nExtremely")) +
labs(y = "", x = "") +
theme(legend.title = element_blank(),
axis.text.y = element_text(face = "bold", size = 11),
axis.text.x = element_text(face = "bold", size = 9)) +
scale_fill_discrete(breaks = c("Appearance", "Aroma", "Flavor",
"Overall", "Aftertaste", "Texture")) +
facet_wrap(~h.names, labeller = labeller(h.names = names.labs)) +
geom_text(aes(label = bar_labels), colour = "white", hjust = 1.7)
#> Error in ggplot(data = df, mapping = aes(x = names, y = value)): could not find function "ggplot"
Created on 2022-01-03 by the reprex package (v2.0.1)