绘制不同图形中的所有行 - 数据框

时间:2014-05-22 08:32:17

标签: r plot

可靠的代码非常简单,但我还没有尝试用R绘图。 我想为每一行和不同图上的所有图绘制线性图。

我的数据中的数字从0到1.值1是绘图的最大值,在某些情况下,单行中的最大值可能很少。我想将pdf文件作为输出。

数据:

> 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").

在pdf中每页顶部有一个行名称会很棒。

1 个答案:

答案 0 :(得分:1)

以下是使用 dputed 数据的示例:

# 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()

第一页是这样的:

enter image description here

如果您想更改图表的样式(例如没有小圆圈的线条等),请查看documentation