Hi,
I have a question, I am using the ggplot2 package for plotting the linear trend using the data frame. The rows contains different timepoints (1, 2, 3) and the columns contain values under the headers (A, B. C, D,.....Z). Using the below code, I can plot only one column per run and save and export it. Is there a way to use or looping all the columns (B, C, D, E,......Z) corresponding to the Timepoints to plot and save it locally on the machine. I have hundreds of columns like this.
Example of a dataframe:
Timepoints A B
1 -1.6774235 2.6583222
2 -1.80880562 2.868172
3 -1.8716294 2.8304835
Code:
library(ggplot2)
library(hrbrthemes)
p3 <- ggplot(dataframe, aes(x=Timepoints, y=A)) +
geom_point() +
geom_smooth(method=lm , color="red", fill="#69b3a2", se=TRUE) +
theme_ipsum()
Thank you,
Toufiq
Thank you so much @Kevin Blighe. This resolved the issue and was very helpful.
Another related query is, I would like to export each of these plots to the .pdf file format to the local drive since I have more elements in the object. i.e
Is this something possible?
Hey, yes, you can modify the code somewhat so that it will work with any number of plots. Here, I do it for 50 groups:
Note that the
margin
part is not required - it just helps to save space. You may also want to break up the plot numbers across multiple pages. Simply run separateplot_grid()
commands for that.Thank you so much Kevin.