How to club these into one figure?

Hello,

I was trying to club these barplots into one figure. If someone can please help me club these?
Sample data is as:

squads <-tibble::tribble(
                  ~test, ~first_res, ~second_res, ~third_res, ~fourth_res, ~fifth_res, ~Frequency,
           "Appearance",       201L,         72L,        54L,         46L,        39L,       412L,
                "Aroma",         8L,         17L,        17L,         24L,        13L,        79L,
               "Flavor",       107L,        148L,       177L,        168L,       122L,       722L,
              "Texture",       151L,        225L,       220L,        198L,       150L,       944L,
             "Abstract",       282L,        260L,       360L,        356L,       402L,      1660L
           )
head(squads)
#> # A tibble: 5 x 7
#>   test       first_res second_res third_res fourth_res fifth_res Frequency
#>   <chr>          <int>      <int>     <int>      <int>     <int>     <int>
#> 1 Appearance       201         72        54         46        39       412
#> 2 Aroma              8         17        17         24        13        79
#> 3 Flavor           107        148       177        168       122       722
#> 4 Texture          151        225       220        198       150       944
#> 5 Abstract         282        260       360        356       402      1660

Created on 2021-05-16 by the reprex package (v2.0.0)

Code can be find below:

tiff(file = "all.tiff", width = 3000, height = 1200, pointsize = 10, units = "px", res = 400)
par(mfrow=c(3,1), mar=c(5,6,1,1)+.1)
#1st OEQ
df <- read.csv("F:/oeq_response.csv")
colnames(df)[1] = "modality"
colnames(df)[2] = "First_response"
colnames(df)[3] = "Second_response"
colnames(df)[4] = "Third_response"
colnames(df)[5] = "Fourth_response"
colnames(df)[6] = "Fifth_response"
dput(df)
#> structure(list(modality = c("Appearance", "Aroma", "Flavor", 
#> "Texture", "Abstract"), 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(412L, 
#> 79L, 722L, 944L, 1660L)), class = "data.frame", row.names = c(NA, 
#> -5L))
colnames(df) <- c("modality","First_response","Second_response","Third_response",
                  "Fourth_response", "Fifth_response", "Frequency")
ggplot(df, aes(x = modality))+
  geom_bar()
#> Error in ggplot(df, aes(x = modality)): could not find function "ggplot"


ggplot(dat, aes(modality, value, fill=interaction(variable))) +
  geom_bar(stat='identity', position='dodge') +
  ggtitle("A: General OEQ") + 
  theme_bw() + theme(axis.text.x = element_text(angle=90, hjust=1, size = 10, face = "bold")) +
  scale_fill_brewer('Open-end', palette='RdPu') +  theme(legend.position = c(.51, .80)) +
  theme(legend.title=element_blank()) +
  xlab("") + ylab("Frequency") + theme(panel.border = element_blank()) + 
  theme(axis.line = element_line(colour = "black")) + 
  theme(legend.key.size = unit(1.0, "cm"), legend.key.width = unit(0.5,"cm"),
        legend.key.height = unit(0.5,"cm")) + 
  theme(legend.text = element_text(size = 7))
#> Error in ggplot(dat, aes(modality, value, fill = interaction(variable))): could not find function "ggplot"

#2nd OEQ
df <- read.csv("F:/second_oeq_frequency.csv")
colnames(df)[1] = "modality"
colnames(df)[2] = "First_response"
colnames(df)[3] = "Second_response"
colnames(df)[4] = "Third_response"
colnames(df)[5] = "Fourth_response"
colnames(df)[6] = "Fifth_response"
dput(df)
#> structure(list(modality = c("Appearance", "Aroma", "Flavor", 
#> "Texture", "Abstract"), First_response = c(9L, 150L, 190L, 10L, 
#> 191L), Second_response = c(1L, 63L, 252L, 37L, 190L), Third_response = c(0L, 
#> 64L, 204L, 53L, 240L), Fourth_response = c(4L, 37L, 184L, 65L, 
#> 264L), Fifth_response = c(2L, 29L, 132L, 43L, 355L), Frequency = c(16L, 
#> 343L, 962L, 208L, 1240L)), class = "data.frame", row.names = c(NA, 
#> -5L))
colnames(df) <- c("modality","First_response","Second_response","Third_response",
                  "Fourth_response", "Fifth_response", "Frequency")
ggplot(df, aes(x = modality))+
  geom_bar()
#> Error in ggplot(df, aes(x = modality)): could not find function "ggplot"

#> Using modality as id variables
ggplot(dat, aes(modality, value, fill=interaction(variable))) +
  geom_bar(stat='identity', position='dodge') +
  theme_bw() + theme(axis.text.x = element_text(angle=90, hjust=1, size = 10, face = "bold")) +
  scale_fill_brewer('Open-end', palette='RdPu') +  theme(legend.position = "none") +
  theme(legend.title=element_blank()) +
  xlab("") + ylab("Frequency") + theme(panel.border = element_blank()) + 
  theme(axis.line = element_line(colour = "black")) + 
  theme(legend.key.size = unit(1.0, "cm"), legend.key.width = unit(0.5,"cm"),
        legend.key.height = unit(0.5,"cm")) + 
  theme(legend.text = element_text(size = 7))
#> Error in ggplot(dat, aes(modality, value, fill = interaction(variable))): could not find function "ggplot"

#3rd OEQ
df <- read.csv("F:/third_oeq_frequency.csv")
colnames(df)[1] = "modality"
colnames(df)[2] = "First_response"
colnames(df)[3] = "Second_response"
colnames(df)[4] = "Third_response"
colnames(df)[5] = "Fourth_response"
colnames(df)[6] = "Fifth_response"
dput(df)
#> structure(list(modality = c("Appearance", "Aroma", "Flavor", 
#> "Texture", "Abstract"), First_response = c(1L, 0L, 1L, 471L, 
#> 97L), Second_response = c(2L, 0L, 7L, 408L, 158L), Third_response = c(11L, 
#> 0L, 11L, 327L, 234L), Fourth_response = c(6L, 0L, 26L, 220L, 
#> 277L), Fifth_response = c(5L, 0L, 27L, 224L, 317L), Frequency = c(25L, 
#> 0L, 72L, 1650L, 1083L)), class = "data.frame", row.names = c(NA, 
#> -5L))
colnames(df) <- c("modality","First_response","Second_response","Third_response",
                  "Fourth_response", "Fifth_response", "Frequency")
ggplot(df, aes(x = modality))+
  geom_bar()
#> Error in ggplot(df, aes(x = modality)): could not find function "ggplot"

#> Using modality as id variables
ggplot(dat, aes(modality, value, fill=interaction(variable))) +
  geom_bar(stat='identity', position='dodge') +
  theme_bw() + theme(axis.text.x = element_text(angle=90, hjust=1, size = 10, face = "bold")) +
  scale_fill_brewer('Open-end', palette='RdPu') +  theme(legend.position = "none") +
  theme(legend.title=element_blank()) +
  xlab("") + ylab("Frequency") + theme(panel.border = element_blank()) + 
  theme(axis.line = element_line(colour = "black")) + 
  theme(legend.key.size = unit(1.0, "cm"), legend.key.width = unit(0.5,"cm"),
        legend.key.height = unit(0.5,"cm")) + 
  theme(legend.text = element_text(size = 7))
#> Error in ggplot(dat, aes(modality, value, fill = interaction(variable))): could not find function "ggplot"
dev.off()
#> png 
#>   2

Created on 2021-05-16 by the reprex package (v2.0.0)

suppressPackageStartupMessages({
  library(ggplot2)
  library(patchwork)
})

dat <- data.frame(modality = c(
  "Appearance", "Aroma", "Flavor",
  "Texture", "Abstract"
), 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(
  412L,
  79L, 722L, 944L, 1660L
))

colnames(dat) <- c("modality","First_response","Second_response","Third_response",
                  "Fourth_response", "Fifth_response", "Frequency")

p1 <- ggplot(dat, aes(modality)) + geom_bar()

p2 <- ggplot(dat, aes(modality, Frequency, fill=interaction(First_response))) + geom_bar(stat='identity', position='dodge') 

p1 + p2

p1 / p2

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.