2014-10-01 109 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