Barplot:修改x軸並添加線

[英]Barplot: changing x axe and adding line


I have a zoo with daily data that looks like this: > head(almorol)
1973-10-02 1973-10-03 1973-10-04 1973-10-05 1973-10-06 1973-10-07
183.9 208.2 153.7 84.8 52.5 35.5

我有一個動物園,每天的數據是這樣的:> head(almorol) 1973-10-02 1973-10-03 1973-10-03 1973-10-04 1973-10-05 1973-10-06 1973-10-07 183.9 208.2 153.7 84.8 54.8 52.5 35.5

I want to plot annual totals and a moving average so I did:

我想畫出年度總數和移動平均線,所以我做了:

y<-apply.yearly(almorol, FUN=sum)
plot(y, main="Annual totals - Tagus (Almorol)",ylab="Q (m3/s)")
lines(rollapply(y, 10, mean, na.rm=TRUE), col="red", lwd=2)

y <應用。年度(almorol, fun="sum)" plot(y, main="Annual total - Tagus (almorol)" ),ylab="“Q" (m3 s)”)線(rollapply(y, 10, mean, na.rm="TRUE)," col="“red”,lwd=2)

Which works fine, but because the data is not continuous a line graph is not correct. If I do it with points is hard to follow so I wanted to do a barplot. However when I do barplot(y) the x axe appears in the format yy-mm-dd instead of just years and I can't add a line with the moving average (it doesn't give an error it just doesn't appear).

這很好,但是因為數據不是連續的,線形圖是不正確的。如果我用點來做,很難理解所以我想做一個條形圖。然而,當我做barplot(y)時,x斧頭以yy-mm-dd格式出現,而不是幾年,我不能用移動平均線加上一條線(它不會產生錯誤,只是不會出現)。

Thanks for helping!

謝謝你的幫助!

edit: > y
1973-12-31 1974-12-31 1975-12-31 1976-12-31
19224.20 103766.30 72180.90 55939.80
1977-12-31 1978-12-31 1979-12-31 1980-12-31
215905.00 231014.21 319481.02 58979.84
1981-12-31 1982-12-31 1983-12-31 1984-12-31
32931.17 67989.06 83920.62 99431.75
1985-12-31 1986-12-31 1987-12-31 1988-12-31
161357.10 82910.87 101154.81 147541.80
1989-12-31 1990-12-31 1991-12-31 1992-12-31
137684.21 134974.39 89039.02 20774.72
1993-12-31 1994-12-31 1995-12-31 1996-12-31
58916.95 55187.38 52361.77 271064.34
1997-12-31 1998-12-31 1999-12-31 2000-12-31
220510.88 125116.62 42170.95 103915.99
2001-12-31 2002-12-31 2003-12-31 2004-12-31
244513.59 66811.15 167458.93 67223.66
2005-12-31 2006-12-31 2007-12-31 2008-12-31
8906.31 116874.33 79105.30 40142.61
2009-12-31 2010-12-31 2011-05-31
43835.34 161491.77 73093.06

編輯:19224.20 103766.30 72182182180.90 5512 - 931 1974-12-31 1974-12-31 1975-12-12-12-31 1975-12-12-31 1975-12-31 1975-12-31 1975-12-31 1975-12-31 1975-12-31 1976-12-31 1976-12-31 1976-12-31 1976-12-31 1976-12-31 1976-12-31 196-12-31 192-31 192-31 192-31 19224.31 192-31 192-31 19224.20 19224.20 19224.20 19144.20 194.20 194.20 194.201997-12-31 1992-12-31 2004-12-31 2004-12-31 2445811.15 167458.66 67223.66 2005-12-31 2001-12-31 2002-12-31 2003-12-31 2004-12-31

1 个解决方案

#1


4  

The x coordinates in a barplot are not related to the original scale of the data. You can look at the return value of the barplot function to see what the range of the x axis is (the probable reason for not seeing the line is it plotted completely off the screen).

barplot中的x坐標與數據的原始比例無關。您可以查看barplot函數的返回值,以查看x軸的范圍是什么(看不到這條線的可能原因是它完全在屏幕之外繪制)。

The updateusr function in the TeachingDemos package can be used to change the coordinate scale to match the data that you want to add.

可以使用TeachingDemos包中的updateusr函數來更改坐標比例,以匹配要添加的數據。

Another alternative is to use the plot function with type='h' (and look at lwd and lend options in ?par) to create your own barplot like plot using the coordinates of interest, then add your reference line.

另一種方法是使用帶有type='h'的plot函數(並查看lwd和lend options in ?par),用感興趣的坐標創建您自己的barplot,然后添加您的參考線。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/06/14/72a0ede567d3d504493a2e4190512cd0.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com