I have an issue and I did not find anything on internet about it. I would be glad to get some hints.
I have a dataset, where the x-axis is discrete, but I would like to connect the points to each other (which I can do). My issue is when I add the faceting option. I cannot link the points to each other anymore. I found an alternative, BUT it does not look great.
This is a simple reproducible example:
# Create a simple dataset
dat <- data.frame(Days = c(rep("Monday", 6), rep("Tuesday", 6), rep("Wednesday", 6)),
Shift = rep(c("Morning", "Evening", "Night"), 6),
Group = c(rep("Group1", 3), rep("Group2", 3), rep("Group1", 3), rep("Group2", 3), rep("Group1", 3), rep("Group2", 3)),
Amount = c(6, 5, 6, 2, 3, 1, 5, 4, 6, 1, 2, 2, 5, 4, 7, 3, 1, 2))
# Change into factor to have the order I need
dat$Days <- factor(dat$Days, levels = c("Monday", "Tuesday", "Wednesday"))
dat$Shift <- factor(dat$Shift, levels = c("Morning", "Evening", "Night"))
# The plot I am stuck with
# The last dot of Monday night should be linked to Tuesday morning
ggplot(data = dat, aes(x = Shift, y = Amount)) + geom_point() +
geom_line(aes(group = Group)) + facet_grid(.~Days) +
theme(panel.spacing = unit(0, "lines"))
# This is the alternative I found, but clearly not great
ggplot(data = dat, aes(x = interaction(Days, Shift, sep = "\n", lex.order = T), y = Amount)) + geom_point(aes(color = Group)) +
geom_line(aes(group = Group)) +
geom_vline(xintercept = c(3, 6, 9),
color = "darkred", linetype = 2)