Reputation: 2279
I'm not an R expert, and I'm having a little troubles plotting my data
Some context: An experiment using 2 coagulants, at 3 different velocities with 3 different solids concentrations was conducted to see the behavior of 3 parameters. The experiment results was recorded in the following data frame:
Coagulant <- c(rep("Chem_1", times = 9),
rep("Chem_2", times = 9))
Velocity <- rep(c(rep("low", times = 3),
rep("mid", times = 3),
rep("high", times = 3)),
times = 2)
Solids <- rep(c(0,50,100), times = 6)
Parameter_1 <- runif(n = 18,
min = 70,
max = 100)
Parameter_2 <- runif(n = 18,
min = 90,
max = 100)
Parameter_3 <- runif(n = 18,
min = 0,
max = 100)
Ex.data.frame <- data.frame(Coagulant,
Velocity,
Solids,
Parameter_1,
Parameter_2,
Parameter_3)
Ex.data.frame$Coagulant <- factor(Ex.data.frame$Coagulant,
levels = c("Chem_1", "Chem_2"),
labels = c("Chem_1", "Chem_2"))
Ex.data.frame$Velocity <- factor(Ex.data.frame$Velocity,
levels = c("low", "mid", "high"),
labels = c("low", "mid", "high"))
Ex.data.frame$Solids <- factor(Ex.data.frame$Solids,
levels = c(0, 50, 100),
labels = c(0, 50, 100))
I'd like to plot this data following this panel separation:
I tried a lot, but only can provide this code to make the plot:
require(ggpubr)
ggbarplot(data = Ex.data.frame,
y = "Parameter_1", #I'd like to use for all parameters (same units)
fill = "Solids",
position = position_dodge2(),
facet.by = c("Coagulant", "??")) #Facet by the parameters columns from the data frame
Upvotes: 0
Views: 197
Reputation: 1076
Here is a potential way towards your goal (you just have to switch in the facet to have the same columns and lines as in your graph) :
library(dplyr)
library(magrittr)
d <-rbind(Ex.data.frame[1:4] %>% rename(Parameter = Parameter_1) %>% mutate(param = "Parameter_1"),
Ex.data.frame[c(1:3,5)] %>% rename(Parameter = Parameter_2) %>% mutate(param = "Parameter_2"),
Ex.data.frame[c(1:3,6)] %>% rename(Parameter = Parameter_3) %>% mutate(param = "Parameter_3")
)
ggbarplot(data = d,
y = c("Parameter" ),
fill = "Solids",
position = position_dodge2(),
facet.by = c( "param", "Coagulant" ))
Upvotes: 1