I have designed an experiment to see how serum markers change with time since eating a meal. I have a data frame consisting of 72 observations and 23o variables this is called BreakfastM.
There are 229 variables which are serum markers and 1 which is timepoint. The observations are different samples
Iam looking for trends in the data of how the serum markers (ie cholestrol) change with the timepoint. I have created a boxplot which shows nicely the trends in a particular serum marker in relation to timepoint
This is the code I used
boxplot((BreakfastM$Variable~BreakfastM$Timepoint))
Is there a quick way to test all the variables in the dataframe against the timepoint by writing a loop code in R?
If you are just looking to plot, converting to long form with
tidyr
(anddplyr
) and then plotting withggplot2
is probably the best starting point.If you have only a small number of variables, you could just use
facet_wrap
to split the boxplots by measure. Because you didn't provide reproducible data, I am using themtcars
data, substituting "gear" for your time point, and limiting to just the numeric values to compare.select
is picking the columns I want to use, thengather
converts them to long format before passing toggplot
Now, with 229 variables, that is not going to be a readable plot. Instead, you may want to look at
facet_multiple
fromggplus
which spreads facets over multiple pages. Here, I am using it to put one per "page" which you can either view in the viewer, or save, depending on your needs.First, save the base plot (with no facetting):
Then, use it as an argument to
facet_multiple
:Will generate the same panels as above, but with one per page (changing
nrow
andncol
can increase the number of facets shown per page).