Reputation: 5
Hi I am a still learning and trying to create a facet plot. I have try googling it but I can't find the right solution for it.
This is the code I used for the plot
met_ven %>%
pivot_longer(c(14, 15, 19, 21, 22, 23, 24, 25, 27, 32, 33, 34),names_to="metabolites",values_to="Concentration") %>%
ggplot(aes(x=factor(Day),y=Concentration)) +
geom_boxplot() +
facet_wrap(~metabolites, scales = "free", ncol = 3) +
labs(title = "Venison")
The plot is showing a concentration of metabolites (y) at certain time point(x) variable are 0, 0.25, 0.79 1.25, 1.75 and 2.25.
From this code the plot giving me
From my understanding, using factor(Day) would put the Day in discrete but I dont want that. I want to do a box plot on a continuous scale.. but if I remove that ti x=Day
ggplot(aes(x=(Day),y=Concentration))
I get this
I want the plot to be like 1 on a continuous scale
Upvotes: 0
Views: 113
Reputation: 37943
If you want boxplots on a continuous scale, you'd have to set the group
aesthetic appropriately. Example without group:
library(ggplot2)
df <- data.frame(
x = sample(1:5, 30, replace = TRUE),
y = runif(30)
)
ggplot(df, aes(x, y)) +
geom_boxplot()
#> Warning: Continuous x aesthetic -- did you forget aes(group=...)?
Including the group:
ggplot(df, aes(x, y, group = x)) +
geom_boxplot()
Created on 2021-10-17 by the reprex package (v2.0.0)
Upvotes: 1