x軸の値として年の日数を使用して、2年連続(たとえば2010年11月5日から2011年3月30日まで)の気温データをプロットしようとしています。例えば:
temp<-c(30.1:40.1) # y axis
doy<-c(360:365,1:5) # x axis
私を助けてください。ありがとう。
temp<-c(30.1:40.1) # y axis
doy<-c(360:365,1:5) # x axis
doy2 <- c(360:365,c(1:5)+365)
plot(temp ~ doy2, xaxt="n", xlab = "doy")
axis(1,doy,at=doy2)
または:
これにアプローチする最も厳密な方法は、R内の日時オブジェクトを使用することです。そうすると、Rは「temp」データを日付として認識し、プロットされたときに正しい結果が得られます。日時オブジェクトは複雑ですが、定期的に扱う場合は、学ぶ価値があります。
temp<-c(30.1:40.1) # y axis
doy<-c(360:365,1:5) # x axis
doy2 <- c(360:365,c(1:5)+365) #we sill need this to place numbers 1:5 into a new year (i.e. 365 days later)
doy.date <- as.Date("2011-01-01") #Set a base date (choose the year that you will start with
doy.date <- doy.date + doy2 - 1 #add the days of year to the base date and subtract one (the base date was January 1st)
plot(temp ~ doy.date, xlab = "doy") #plot as usual
#see documentation on dates
?date
#or for date with times:
?POSIXct