[R] combining/overlaying boxplot and barplot
Soenario, Ivan (KNMI)
Ivan.Soenario at knmi.nl
Mon Oct 12 18:56:10 CEST 2009
I would like to visualise when days are rainy or dry in bar/boxplots.
Therefore I've tried to combine raingauge data (boxplots) and percentage
of raingauges with 0mm measurements (barplot). See attachment
mei2004.pdf (if it came through).
I've come this far:
barplot(dcp0[monthindex], col="gray", border=NA, axes=F)
boxplot(t(dcpn[monthindex,]), names=dates$day[monthindex], main=month,
outline=F, add=T, ylim=c(0,30), col="lightblue")
Both plots use different x-axis spacing, so May 31 of the barplot
extents further to the right than May 31 boxplot.
So, how do I get the x-axis of both plots aligned?? I've looked at par()
but can't see any parameters for plot size. Only for inner and outer
The strange thing is, when I plot the boxplot (add=F), it uses more
x-axis space (on the same device), the graph becomes wider (with add=T,
it does seem to take the numbers from the barplot in to account).
Thanks for the help!
Royal Netherlands Meteorological Institute
dcpn: data.frame containing raingauge data for 310 stations (columns)
for 1991-2006 (each day is a row)
dcp0: calculation of % 0mm, based on dcpn.
monthindex: array with rownumbers, in this case representing month May
in 2004 (so length(monthindex) is 31)
I cheated with percentage, I multiplied the fraction (number of
0mm)/(total number raingauges) with 30, to make it fit with the
boxplot's ylim of 30. It seldomly rains more than 30mm in 24hours.
To overcome this, I'd need to draw the barplot with it's own y-axis,
and, the boxplot shouldn't notice/use the ylim from the barplot.
More information about the R-help