[R] Adding overlap legend to a histogram

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Fri May 8 02:12:56 CEST 2020


Hi Ogbos,
I don't think that your example allows us to work out what you are
trying to do. For one thing, "x1" and "x2" do not overlap. Also, you
are plotting the frequencies of dates of observations, which may not
be what you want.
The following code will correctly display your example:

hist(x1,breaks="years",freq=T,axes=F,xlim=c(9400,11100),col=c1a)
hist(x2,breaks="years",freq=T,axes=F,add=T,col=c2a)
 axis.Date(1, at=seq(as.Date(min(x1)), as.Date(max(x2)), by="years"))
 axis(2)
legend("topleft", c("AUTO", "MANUAL"), fill=c("red", "blue"))

What it is displaying is the frequency of observations in your two
vectors by calendar year. If this is what you want, and you can
explain how you would like "overlap" to be displayed, we can probably
provide better help.

Jim


On Fri, May 8, 2020 at 7:01 AM Ogbos Okike <giftedlife2014 using gmail.com> wrote:
>
> Dear Experts,
> Greetings.
>
> I am trying to display two datasets in a histogram. I have been able to
> plot the graph and added the legend for the two colors. I am, however,
> having difficulties adding a legend to represent the regions of overlap
> (the third legend).  Below are my data and code.



More information about the R-help mailing list