Shaxi Liver
Shaxi Liver

Reputation: 1120

Plotting all of the rows in different graph - data frame

Propably the code is very simple but I have never tried plotting in R yet. I would like to have a linear plot for every row and all the plots on different graph.

The number in my data goes from 0 to 1. Value one is the maximum of the plot, in some cases there might be few maximums in a single row. I would like to have a pdf file as an output.

Data:

> dput(head(tbl_end))
structure(list(`NA` = structure(1:6, .Label = c("AT1G01050", 
"AT1G01080", "AT1G01090", "AT1G01220", "AT1G01320", "AT1G01420", 
"ATCG00800", "ATCG00810", "ATCG00820", "ATCG01090", "ATCG01110", 
"ATCG01120", "ATCG01240", "ATCG01300", "ATCG01310", "ATMG01190"
), class = "factor"), `10` = c(0, 0, 0, 0, 0, 0), `20` = c(0, 
0, 0, 0, 0, 0), `52.5` = c(0, 1, 0, 0, 0, 0), `81` = c(0, 0.660693687777888, 
0, 0, 0, 0), `110` = c(0, 0.521435654491704, 0, 0, 0, 1), `140.5` = c(0, 
0.437291194705566, 0, 0, 0, 1), `189` = c(0, 0.52204783488213, 
0, 0, 0, 0), `222.5` = c(0, 0.524298383907171, 0, 0, 0, 0), `278` = c(1, 
0.376865096972469, 0, 1, 0, 0), `340` = c(0, 0, 0, 0, 0, 0), 
    `397` = c(0, 0, 0, 0, 0, 0), `453.5` = c(0, 0, 0, 0, 0, 0
    ), `529` = c(0, 0, 0, 0, 0, 0), `580` = c(0, 0, 0, 0, 0, 
    0), `630.5` = c(0, 0, 0, 0, 0, 0), `683.5` = c(0, 0, 0, 0, 
    0, 0), `735.5` = c(0, 0, 0, 0, 0, 0), `784` = c(0, 0, 0.476101907006443, 
    0, 0, 0), `832` = c(0, 0, 1, 0, 0, 0), `882.5` = c(0, 0, 
    0, 0, 0, 0), `926.5` = c(0, 0, 0, 0, 1, 0), `973` = c(0, 
    0, 0, 0, 0, 0), `1108` = c(0, 0, 0, 0, 0, 0), `1200` = c(0, 
    0, 0, 0, 0, 0)), .Names = c(NA, "10", "20", "52.5", "81", 
"110", "140.5", "189", "222.5", "278", "340", "397", "453.5", 
"529", "580", "630.5", "683.5", "735.5", "784", "832", "882.5", 
"926.5", "973", "1108", "1200"), row.names = c(NA, 6L), class = "data.frame").

Would be great to have a name of the row on the top of each page in pdf.

Upvotes: 0

Views: 314

Answers (1)

digEmAll
digEmAll

Reputation: 57210

Here's an example using your dputed data:

# open the pdf file
pdf(file='myfile.pdf')

# since I don't know what values should be on the X axis, 
# I'm just using values from 1 to number of y-values
x <- 1:(ncol(tbl_end)-1) 

for(i in 1:nrow(tbl_end)){
  # plot onto a new pdf page 
  plot(x=x,y=tbl_end[i,-1],type='b',main=tbl_end[i,1],xlab='X',ylab='Y')
}

# close the pdf file
dev.off()

where the first page is something like this:

enter image description here

If you want to change the style (e.g. lines without the little circles etc.) of the plot, have a look at the documentation.

Upvotes: 1

Related Questions