2014-10-01 107 views
2

点的名字,我用下面的代码做一个图:更改X轴

# 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

像这样的东西应该工作:

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) 
+0

你能用我的数据编辑你的答案吗?我不确定我该怎么做。 – 2014-10-01 13:55:53

+0

当然,如果你能提供一个[可重现的exmpale](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – johannes 2014-10-01 14:28:53

+0

添加了我的数据+图表。当然你会使用不同的行,因为我不能把我的整个数据放在这里,所以图的外观可能会不同。 – 2014-10-01 15:25:27