Entering edit mode
9.5 years ago
yasjas
▴
70
Hi all,
I tried to make a boxplot for each classes of (data
) based on repeat names (rep_name
) with a for loop but it didn't give me the desired result. What it gave me was the last boxplot of the last class
Any idea on how I can have a boxplot for each class with a loop instead of doing it manually?
Thanks for any answer
for (i in length(data)){
boxplot(data[[i]][5:8])
}
data
[[1]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2
LTR18B LTR NDUFAB1 572 9.3038 9.287 10.9524 10.8579
[[2]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2
LTR19B LTR CASP10 0 6.5334 5.3218 7.1686 5.9633
LTR19B LTR CD38 0 5.8011 6.9873 5.7066 2.5126
[[3]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2
LTR4 LTR ACSM3 0 8.744 6.9615 5.9441 3.1032
[[4]]
rep_name rep_family gene distance Hepatocytes_B1 Hepatocytes_B3 Huh.7_B1 Huh.7_B2
LTR53 LTR TNMD 66637 0.5905 0.9610 0.6130 0.7612
LTR53 LTR MTMR7 0 3.9547 3.7264 3.5522 4.2649
LTR53 LTR VPS41 2226 7.1890 7.2522 7.1952 7.0576
The for cycle must be:
Oh, ya, I forgot to check his code. That also explain why he will only ever see the last boxplot.
Further explanation on graphing in R:
When you call
boxplot()
(or any graphing function) in R, it draws it in a default graphic device, which it closes after you're done. Every time you call anotherboxplot()
function, it overwrites your previous plot. What Sam suggests above is opening your own graphics device manually (in this case, a pdf), write what output you want to it, and then close it.A couple of things to keep in mind: be sure to close the graphic device explicitly with
dev.off()
, and be careful with using loops to write files, since if your loop is incorrect and turns out to be an infinite loop, you will create a huge file and potentially cause issues.Thank you guys, it is more clear now and thanks for the link of the tutorial