First of all, I am very new to both R and stackoverflow so I apologize for any formatting issues. I am trying to plot many individuals separately, but when I use facet_wrap
, there are too many plots, so they are all very small and impossible to see. I switched to facet_wrap_paginate
and the plots are almost perfect... except the x axis label is missing!
My code (using ggplot2 and ggforce):
library(ggplot2)
library(ggforce)
lb <- c("8AM", "2PM", "8PM", "2AM", "8AM")
L <- 1440
xat <- c(1, L/4, L/2, 3*L/4, L)
Baseline1 <- ggplot(Baseline.df_long,
aes(x = Minute, y = value, color = key, group = key)) +
facet_wrap_paginate(~ key, ncol = 3, nrow = 3, page = 1, scales = "free_x") +
geom_bar(stat = "identity") +
scale_y_continuous(breaks=seq(0, 2500, 500), limits =c(0,2500)) +
scale_x_discrete(name="Time", breaks=c(xat), labels=c(lb)) +
labs(title ="Piglet Activity", y = "Activity") +
theme_bw(base_size = 14) +
theme(legend.position = "none")
I have tried both with and without scales = "free x"
, I also tried fixed. None of these make a difference. This is what it looks like currently with the missing x axis labels:
This is what I would like the label to look like, and I was able to do it using a single column with facet_wrap for a single individual:
For reference so you know what kind of data set this is, Baseline.df_long
looks like this, but obviously with much more data
structure(list(Minute = 1:50, key = c("Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03",
"Pig_03", "Pig_03", "Pig_03", "Pig_03", "Pig_03"), value = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 165L, 23L, 0L, 0L,
0L, 0L, 12L, 0L, 0L, 0L, 0L, 0L, 0L, 81L, 0L, 0L, 12L, 12L, 0L,
0L, 47L, 0L, 0L, 12L, 23L, 0L, 0L, 0L, 0L, 0L, 0L, 105L, 70L,
47L, 0L, 0L, 0L, 0L)), row.names = c(NA, -50L), class = "data.frame")