species | seed type | germination time |
---|---|---|
A | initial | 10.5 |
A | initial | 11.3 |
B | stored | 12.5 |
about data There are 34 species, 2 seed types (stored and initial), germination time is numerical.
What I need to create is something similar to the attached image. The main thing is that it needs to be created using ggplot
I tried to wrap pannels using the following code
plot2 <- ggplot(mydata, aes(x=factor(species), y=mgt,fill = species))+
geom_boxplot(outliers = F)+ theme(legend.position = "bottom")
plot3 <- plot2 + coord_flip()+ facet_wrap(seed_type) + scale_x_discrete(name = "Seed Type") + scale_y_continuous(name = "Germination Time")
plot3
But it didn't create the figure I wanted.
library(tidyverse)
# create some fake data
my_data <- data.frame(
species = sample(LETTERS[1:3], 100, replace = TRUE),
seed_type = sample(paste0("seed_type_", letters[1:8]), 100, replace = TRUE),
germination_time = runif(100, 10, 12.5)
)
head(my_data)
ggplot(my_data, aes(x = factor(species), y = germination_time, fill = species))+
geom_boxplot(outliers = F)+
theme(legend.position = "bottom") +
facet_wrap(~seed_type, ncol = 4) +
scale_x_discrete(name = "Species") +
scale_y_continuous(name = "Germination Time")