0

I'm using ggboxplot and the "facet.by" argument. The default makes a facet horizontally, but I would like my plot to facet'ed vertically (ie. they all share the same x-axis: "Age"). I have scanned SO and other websites but haven't seen this question asked.

I have also tried filtering my dataframe by the same "facet.by" categorical variable and then using cowplot's plot_grid and gridExtra's grid.arrange function. The problem with cowplot and gridExtra is that they both remove my scale_y_beak() setting. I tried using free_y but that now creates three different y axes for my plot and I would like to apply just one y axis to all three plots.

My question: Is there a way to use the built in facet function in ggboxplot to facet by "tetramer" horizontally?

Thank you!

My code for the ggboxplot that uses the "facet.by" argument:

ggboxplot(OnlyClusterCandB, x= "time", y="Ratio_Activated_to_Unactivated", facet.by = "tetramer", fill = "tetramer", title = "Ratio of Activated insulin specific cells to
   Unactivated cells over time", error.plot = "errorbar", desc_stat =
   "mean_se") +    
stat_summary(fun = median, geom = 'line', aes(group =
   "tetramer"), position = position_dodge(width = 0.9)) +  
   rotate_x_text(angle = 45) +    
scale_y_break(c(3,5), ticklabels =
   c(0,6)) +  
ylab("Ratio of activated to inactivated tetramer specific
   cells") +   
xlab("Age of Mice (Weeks)") +     theme(legend.position =
   "none") +   
ggtitle("Change in activation status of circulating
   tetramer specific CD4 T cells") +    
theme(plot.title =
   element_text(size = 16, hjust = 0.5)) +  
theme(axis.text=element_text(size=14)) + 
theme(axis.title.x=element_text(size=14)) +   
theme(axis.title.y =element_text(size=14))

enter image description here

AdvBegR
  • 19
  • 2
  • Your question isn't reproducible, but have you tried using the package `trelliscopejs`? Instead of using the faceting parameter in this function add `+ facet_trelliscope(~tetramer, nrow = 2, ncol = 3)` (Assuming that you have 6 facets.) You may want to drop all the theme elements initially, just to see if it works for you. This is good for data with shared axes. You could alternatively try `plot_layout` from the package `patchwork`, but that's more for unshared axes. Another package for generating the plots is another idea. – Kat May 08 '22 at 06:03

1 Answers1

0

Have you tried using coord_flip() after facetting as seen here?

U_jex
  • 83
  • 6