2017-09-15 122 views
0

我有一個數據幀是這樣的:如何在散點圖的x軸上獲得更好的日期間隔?

Days  Ahm5 
01/06/1961 0.00000 
02/06/1961 0.19266 
03/06/1961 1.67610 
........ ........ 
30/09/1961 5.26514 
01/06/1962 0.05200 
......... ........ 
30/09/2007 0.866473 

這裏的數據:https://www.dropbox.com/s/de88gqk7kvb1q9i/data.csv?dl=0 當我嘗試散點圖一樣,

data <- read.csv("data.csv") 
data[data==-9.99e+08] = NA      
data$days <- as.Date(data$days, format="%d/%m/%Y") 
plot(Ahm5~days,data, col='blueviolet', type="p", pch=1 ,cex=.5, xlab="Year",xaxt='n', ylab="Rainfall(mm/Day)") 
axis.Date(side=1,seq(as.Date("1961/1/1"), by = "year", length.out = 47)) 

輸出是這樣的。 enter image description here

但我需要的輸出應該像下面的數據給出x軸跨度1960年至2007年的數字:

enter image description here 還怎麼上年增加X軸?對不起,這個小問題。

+0

請包括[再現的示例](HTTP:/ /stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610)。這使得其他人更容易幫助你。 – Jaap

+0

使用我使用的數據和代碼編輯。 – ajilesh

回答

2

你必須確保劇情足夠寬,否則一些休息時間將被省略。請參閱下面的示例以瞭解其差異。

實施例1:

png(filename = 'scatterplot1.png', width = 800, height = 400) 
plot(Ahm5 ~ days, dat, col = 'blueviolet', type = "p", pch = 1, cex=.5, xlab = "Year", xaxt='n', ylab = "Rainfall (mm/Day)") 
axis.Date(side = 1, at = seq(as.Date("1961/1/1"), by = "year", length.out = 47)) 
dev.off() 

給出:

enter image description here

實施例2:

png(filename = 'scatterplot2.png', width = 600, height = 300) 
plot(Ahm5 ~ days, dat, col = 'blueviolet', type = "p", pch = 1, cex=.5, xlab = "Year", xaxt='n', ylab = "Rainfall (mm/Day)") 
axis.Date(side = 1, at = seq(as.Date("1961/1/1"), by = "year", length.out = 47)) 
dev.off() 

給出:

enter image description here

實施例3:

png(filename = 'scatterplot3.png', width = 400, height = 200) 
plot(Ahm5 ~ days, dat, col = 'blueviolet', type = "p", pch = 1, cex=.5, xlab = "Year", xaxt='n', ylab = "Rainfall (mm/Day)") 
axis.Date(side = 1, at = seq(as.Date("1961/1/1"), by = "year", length.out = 47)) 
dev.off() 

給出:

enter image description here

正如可以看到斷曲線和R選擇打破使用不同。爲了擁有更好的休息,你可以使用:

png(filename = 'scatterplot4.png', width = 800, height = 400) 
plot(Ahm5 ~ days, dat, col = 'blueviolet', type = "p", pch = 1, cex=.5, xlab = "Year", xaxt='n', ylab = "Rainfall (mm/Day)") 
axis.Date(side = 1, at = seq(as.Date("1965/8/1"), by = "5 year", length.out = 9)) 
dev.off() 

這給:

enter image description here

現在您有:

  • 一些好的休息
  • 蜱中間對齊每年'散射樁'。

UPDATE:上的最後一個示例的進一步的闡述:

png(filename = 'scatterplot5.png', width = 800, height = 400) 
plot(Ahm5 ~ days, dat, col = 'blueviolet', type = "p", pch = 1, cex=.5, 
    xlab = "Year", xaxt='n', ylab = "Rainfall (mm/Day)") 
axis.Date(side = 1, 
      at = c(seq(as.Date("1960/8/1"), by = "10 year", length.out = 5), 
       as.Date('2007-08-01'))) 
dev.off() 

其給出:

enter image description here

+0

感謝您的回覆,它有幫助。但我再次編輯了我的問題,以澄清我在找什麼。 – ajilesh

+0

@ajilesh查看更新。那是你在找什麼? – Jaap

+0

請看我在問題中給出的兩張圖。我不想在一年中堆積日期。 – ajilesh