Hi,
I am using the ggplot2 library for plotting the line graph using the data frame as given below. The rows contains different timepoints (1, 2, 3, 4, 5, 6) and the columns contain values under the headers (Gene A, Gene B, Gene C, Gene D). Using the below code, I could generate 4 different plots each one for a particular gene. Please let me know if there is way to include all 4 genes in one plot instead of individual one's. Screen of the individual plot also attached for reference.
B1_v1_sorted
Timepoints Gene A Gene B Gene C Gene D
1 -0.757847 -0.404452 2.46365 -1.174
2 -0.0461316 -0.276019 2.87773 -1.01407
3 -1.35582 -0.47392 2.31436 -3.21155
4 -1.11589 -0.653023 1.27958 -1.32141
5 -1.63586 -1.64114 0.786856 -1.24327
6 -2.29268 -2.04769 -0.826819 -4.12988
library(ggplot2)
library(hrbrthemes)
p_v1 <- lapply(
colnames(B1_v1_sorted)[2:ncol(B1_v1_sorted)],
function(col) ggplot(B1_v1_sorted, aes_string(x = 'Timepoints', y = col)) +
geom_line())
p_v1
require(cowplot)
plot_grid(
p_v1[[1]], p_v1[[2]], p_v1[[3]], p_v1[[4]],
ncol = 4,
labels = colnames(B1_v1_sorted)[2:5])
Thank you,
Toufiq
Explained in this post. Kindly refer.
@Chirag Parsania, thank you for the suggestions. I could get the expected plots.
I have two questions,
This is plotted just with the few IDs (last column), I have more than hundred IDs and saving the pdf looks fuzzy. Is there a way to include all the plots corresponding to the ID by setting margins in the pdf report.
Include the gene names inside each ID box, as separate legend occupies more space and not very interpretive in case of large data.
dput(head(final))
In the plot above you showed, you should make
value
column tonumeric
rathercharacter
. It will make your y-axis visually look much better than current. Also, if you have more than 100 genes to show each with name of each in legend, probably line plot is not a good idea. Better you use heatmap.@Chirag Parsania,
Thank you for the observation. Yes, the y-axis now looks better.