更改X轴的点名称

时间:2014-10-01 13:11:12

标签: r

我使用下面的代码制作图表:

# open the pdf file
pdf(file='LSF1_PWD_GWD.pdf')
a <- c('LSF1', 'PWD', 'GWD')
rowsToPlot<-c(1,3,4)
matplot(as.matrix(t(tbl_alles[rowsToPlot,])),type=rep("l", length(rowsToPlot)), col=rainbow(length(rowsToPlot)),xlab = 'Fraction Size', ylab = 'Intensity')
legend('topright',a,lty=1, bty='n', cex=.75, col = rainbow(length(rowsToPlot)))
# close the pdf file
dev.off()

但我“不喜欢”X轴上的名字。比例很好,但我想将数字从1:25更改为向量name_xaxis

> name_xaxis
 [1] "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" 
[14] "581.46"  "651.71"  "732.59"  "817.56"  "896.24"  "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.406068869, 0.442796386
), `84.42` = c(0, 1, 0, 0, 1, 1), `110.21` = c(0, 0.740141948, 
0, 0, 0, 0), `134.16` = c(0.145120216, 0, 0, 0, 0, 0), `164.69` = c(0.469210651, 
0, 0.718559026, 0, 0, 0), `199.1` = c(1, 0, 0.407942079, 0, 0, 
0), `234.35` = c(0.872554735, 0, 0.36848211, 0, 0, 0), `257.19` = c(0.607531831, 
0, 0.732164761, 0, 0, 0), `361.84` = c(0.448884106, 0.915113972, 
1, 0, 0, 0), `432.74` = c(0.527332473, 1, 0.638970429, 0, 0, 
0), `506.34` = c(0, 0, 0, 0, 0, 0), `581.46` = c(0, 1, 0.51988094, 
0, 0, 0), `651.71` = c(0, 0.57768664, 0.61355208, 0.56951949, 
0, 0), `732.59` = c(0, 0.53256077, 0.66151388, 0.3963868, 0, 
0), `817.56` = c(0, 0.44040018, 1, 0.74806138, 0, 0), `896.24` = c(0, 
0.591717841, 0.967059269, 0.801504496, 0, 0), `971.77` = c(0, 
0, 0.863936222, 0.783134862, 0, 0), `1038.91` = c(0, 0, 0.83156426, 
1, 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")

enter image description here

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

a <- matrix(rnorm(100), ncol=2)
matplot(a, xaxt="n")
axis(1, at=seq(1, 50, 5), labels=paste("A", seq(1, 50, 5)))

编辑1:

这会有用吗?

a <- c('LSF1', 'PWD', 'GWD')
rowsToPlot<-c(1,3,4)
name_xaxis <- c(10, 33.95, 58.66, 84.42)

matplot(
    as.matrix(t(tbl_alles[rowsToPlot,])),
    type=rep("l", length(rowsToPlot)),
    col=rainbow(length(rowsToPlot)),
    xlab = 'Fraction Size',
    ylab = 'Intensity',
    xaxt="n")

legend('topright',a,lty=1, bty='n', cex=.75, col = rainbow(length(rowsToPlot)))

axis(1, at=name_xaxis)