2013-02-25 63 views
0

我想將2002年至2011年的x軸值分別顯示爲2002年至2011年的每個顯示數據的對應boxplot圖。一定有一些竅門!如何放置x軸值

代碼:

d = read.table("C:/sample.txt", sep="\t", header=TRUE) 
attach(d) 
summary(d) 
boxplot(2002, 2003,2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 
     data=d, boxcol="blue", medcol="red", whiskcol="blue", 
     staplecol="blue", ylim = c(0, 1), lty=1, las=1, ylab = "NDVI", 
     outline = FALSE, boxfill = FALSE) 

的樣本數據

2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 
0.8392 0.8337 0.8145 0.8306 0.8545 0.7876 0.8491 0.8568 0.8459 0.8778 
0.8251 0.7509 0.7301 0.7829 0.8103 0.7368 0.7122 0.685 0.7623 0.8159 
0.8584 0.8217 0.8105 0.8295 0.8382 0.769 0.8265 0.8287 0.8344 0.8204 
0.8651 0.8211 0.8346 0.8624 0.8629 0.7926 0.8543 0.8648 0.8456 0.8656 
0.7991 0.7653 0.7512 0.8106 0.8354 0.7013 0.752 0.8256 0.8235 0.7579 
0.8572 0.8186 0.8009 0.6988 0.719 0.7645 0.8142 0.8164 0.7529 0.7214 
0.8483 0.8159 0.833 0.8401 0.8426 0.7777 0.8608 0.8243 0.8426 0.8602 
+1

我試圖格式化你的代碼,以便它是可讀的,但你的電話箱線圖看起來像廢話給我。你能否檢查它並確保它與你實際運行的相匹配? – joran 2013-02-25 04:22:47

+0

boxplot(2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,data = d,boxcol =「blue」,medcol =「red」,whiskcol =「blue」,staplecol =「blue」 ,ylim = c(0,1),lty = 1,las = 1,ylab =「NDVI」,outline = FALSE,boxfill = FALSE) – arjm 2013-02-25 04:34:58

回答

3

您對boxplot電話是錯誤的。

見下文。

> df <- read.table(textConnection('2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 
+ 0.8392 0.8337 0.8145 0.8306 0.8545 0.7876 0.8491 0.8568 0.8459 0.8778 
+ 0.8251 0.7509 0.7301 0.7829 0.8103 0.7368 0.7122 0.685 0.7623 0.8159 
+ 0.8584 0.8217 0.8105 0.8295 0.8382 0.769 0.8265 0.8287 0.8344 0.8204 
+ 0.8651 0.8211 0.8346 0.8624 0.8629 0.7926 0.8543 0.8648 0.8456 0.8656 
+ 0.7991 0.7653 0.7512 0.8106 0.8354 0.7013 0.752 0.8256 0.8235 0.7579 
+ 0.8572 0.8186 0.8009 0.6988 0.719 0.7645 0.8142 0.8164 0.7529 0.7214 
+ 0.8483 0.8159 0.833 0.8401 0.8426 0.7777 0.8608 0.8243 0.8426 0.8602'), header=TRUE) 
> boxplot(df, names=2002:2011) 

enter image description here

如果你在你的例子指定調用boxplot與其他參數,你就會得到以下。

> boxplot(df, names=2002:2011, boxcol="blue", 
      medcol="red", whiskcol="blue", staplecol="blue", 
      ylim = c(0, 1), lty=1, las=1, ylab = "NDVI", 
      outline = FALSE, boxfill = FALSE) 

enter image description here

+0

+1我只是縮進你的代碼。 – agstudy 2013-02-25 05:09:18

+0

非常感謝! – arjm 2013-02-25 05:11:59

+0

@arjm如果滿意,你能接受並接受答案嗎? – 2013-02-25 06:30:26