我试图在图表中添加图例。你能告诉我我做错了吗?
a <- c('LSF1', 'PWD', 'GWD')
# open the pdf file
pdf(file='LSF1_PWD_GWD.pdf')
rowsToPlot<-c(93,2018,942)
matplot(as.matrix(t(tbl_alles[rowsToPlot,])),type=rep("l", length(rowsToPlot)), col=rainbow(length(rowsToPlot)),xlab = 'Fraction Size', ylab = 'Intensity',
legend('topright', names(a),lty=1, bty='n', cex=.75))
# close the pdf file
dev.off()
出现的错误:
Error in as.graphicsAnnot(legend) :
argument "legend" is missing, with no default
我想更改X轴上的列数(从1到25)作为列的名称,但保持比例不变。
colnames(tbl_alles)
[1] "10" "33.95" "58.66" "84.42" "110.21" "134.16" "164.69" "199.1" "234.35"
[10] "257.19" "361.84" "432.74" "506.34" "581.46" "651.71" "732.59" "817.56" "896.24"
[19] "971.77" "1038.91"
这是我的数据:
> dput(head(tbl_alles))
structure(list(`10` = c(0, 0, 0, 0, 0, 0), `33.95` = c(0, 0,
0, 0, 0, 0), `58.66` = c(0, 0, 0, 0, 0.328143363, 0.552139556
), `84.42` = c(0, 0, 0, 0, 1, 1), `110.21` = c(0, 0, 0, 0, 0,
0.151581882), `134.16` = c(0.190968551, 0, 0, 0, 0, 0.164736594
), `164.69` = c(0.5342874459, 0, 0.3619993464, 0, 0, 0.1891527151
), `199.1` = c(0.866134859, 0, 0.405387979, 0, 0, 0.274468991
), `234.35` = c(1, 0, 0.446118481, 0, 0, 0.338427523), `257.19` = c(0.732231652,
0, 0.666653103, 0, 0, 0.403078017), `361.84` = c(0.660960044,
0, 1, 0, 0, 0.202578329), `432.74` = c(0.47961801, 0, 0.48323321,
0, 0, 0.25926071), `506.34` = c(0, 0, 0, 0, 0, 0), `581.46` = c(0,
0.52783556, 0, 1, 0, 0), `651.71` = c(0, 0.32678969, 0, 0.36428195,
0, 0), `732.59` = c(0, 0.229023369, 0, 0.312832425, 0, 0), `817.56` = c(0,
0.25668583, 0, 0.4003249, 0, 0), `896.24` = c(0, 0.31675535,
0, 0.50882005, 0, 0), `971.77` = c(0, 0.27811949, 0, 0.48419038,
0, 0), `1038.91` = c(0, 1, 0, 0.52506752, 0, 0)), .Names = c("10",
"33.95", "58.66", "84.42", "110.21", "134.16", "164.69", "199.1",
"234.35", "257.19", "361.84", "432.74", "506.34", "581.46", "651.71",
"732.59", "817.56", "896.24", "971.77", "1038.91"), row.names = c("at1g01050.1",
"at1g01080.1", "at1g01090.1", "at1g01320.2", "at1g01470.1", "at1g01800.1"
), class = "data.frame")
答案 0 :(得分:3)
legend(...)
的来电
那是:
matplot(...)
这有帮助吗?
编辑:
事实证明,您的图例是matplot(as.matrix(t(tbl_alles[rowsToPlot,])),type=rep("l", length(rowsToPlot)), col=rainbow(length(rowsToPlot)),xlab = 'Fraction Size', ylab = 'Intensity')
legend('topright', names(a),lty=1, bty='n', cex=.75)
的内容(即,a
已经是名称的向量 - 无需调用a
)。显示图例的右侧调用变为:
names(a)
然后它适用于提供的数据集。
编辑2:
说实话,这就是我的电脑上可以使用的内容:
legend('topright', a,lty=1, bty='n', cex=.75)
这给出了:
它应该在新的R会话中为你工作:)