I am having trouble getting proper labeling of my x axis when making a bar plot. I am faceting by timepoint, and since I have some subjects who do not have samples for every timepoint, I want there to be a blank space if there is a missing sample, so that you can still read across the faceted plots and easily follow each subject over time.
It seems to me like facet_grid() is the only function that will get me what I need in terms of having blank spaces for empty samples. (facet_wrap(), facet_nested(), and the built in "facet_by=" in comp_barplot() did not work).
However, if I use facet_grid() and specify aes(x=Subject), the subject numbers are not appearing on the axis. If I comment out the aes() and instead use "label=" in comp_barplot(), this results in a hugely messy graph because it repeats each subject on the axis.
Not sure I explained that well. Here is my code, and an example of the plot using aes() specifications and using "label="
specifications.
genusplot <- phygenus_plot %>%
comp_barplot(
tax_level = "Genus",
n_taxa = 24,
label = "Subject",
sample_order = samples
) +
geom_bar(stat = "identity")+
coord_flip() +
facet_grid(~Timepoint, scales = "free") +
#aes(x = Subject) +
guides(fill = guide_legend(reverse = TRUE, keywidth = 0.4, keyheight = 0.4, nrow=5)) +
labs(y = "Relative Abundance", fill = "Genus") +
theme_classic() +
theme(plot.title = element_text(hjust=0.5, size = 15),
axis.text.x = element_text(size = 9, hjust = 0.5, colour=1),
axis.text.y = element_text(size = 9, colour=1),
axis.title.x = element_text(size=13),
axis.title.y = element_text(size=13),
legend.text = element_text(size = 8),
legend.key.size = unit(0.4, "cm"),
legend.key.width = unit(0.4,"cm"),
legend.position = "bottom",
strip.text.x = element_text(size=10),
strip.text.y = element_text(size=10),
panel.border = element_rect(colour = "black", fill=NA),
axis.text = element_text(colour = 1, size = 9)
)
genusplot
![image](https://user-images.githubusercontent.com/108419227/178817753-2add1a02-6ece-4990-843c-03cca4c072c7.png)
![image](https://user-images.githubusercontent.com/108419227/178818306-7fcca718-684f-4192-8b03-f252f52ff689.png)