Saturday 15 August 2015

r - How to loop through and produce plots on the same page -



r - How to loop through and produce plots on the same page -

i have genetic info trying plot out on per chromosome basis. code follows:

plot(df[which(df[,1] == "chr7"),2],p_seq[which(df[,1] == "chr7")],type="l",lty=4,xlab="locus",ylab="median zscore")

the dataframe (called df) has chromosomes in first column labelled chr1, chr2 etc chr22 , chrx , chry.

i above plot chr in column 1 , have them on same page. seek , loop through chr , number x chrx , y ruin this. can help?

without reproducible example, can't sure if fits you're trying do, here 2 ways multiple plots @ once. i've used mtcars info set, built r:

# pdf file separate page each plot pdf("plots.pdf", 5,5) # create separate plot of mpg vs. weight each value of cyl (i in unique(mtcars$cyl)) { plot(mtcars$wt[mtcars$cyl==i], mtcars$mpg[mtcars$cyl==i], xlab=paste0(i," cylinders"), ylab="mpg") } dev.off() # pdf file plots on 1 page pdf("plots2.pdf", 5,12) # set 3 plots in 1 column on single page par(mfrow=c(3,1)) # create separate plot of mpg vs. weight each value of cyl (i in unique(mtcars$cyl)) { plot(mtcars$wt[mtcars$cyl==i], mtcars$mpg[mtcars$cyl==i], xlab=paste0(i," cylinders"), ylab="mpg") } dev.off()

r

No comments:

Post a Comment