[R] [FORGED] Re: Generating a Special Histogram
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Jan 6 00:50:03 CET 2017
On 05/01/2017 5:21 PM, Rolf Turner wrote:
> On 06/01/17 10:31, Jim Lemon wrote:
>> Hi Dan,
>> This may help if your data is in the format below:
>>
>> waffle.mat<-matrix(c(rep(NA,14),137,135,rep(NA,6),144,149,
>> rep(NA,3),150,152,159,157,154,
>> NA,163,164,164,161,162,165,164,rep(NA,5),179,173,173,
>> rep(NA,4),182,180,185,180,
>> rep(NA,6),197,190,rep(NA,8)),ncol=9)
>> waffle.col<-matrix("lightblue",ncol=9,nrow=8)
>> waffle.col[is.na(waffle.mat)]<-NA
>> waffle.border<-matrix("blue",ncol=9,nrow=8)
>> waffle.border[is.na(waffle.mat)]<-NA
>> library(plotrix)
>> # use a waffle plot
>> color2D.matplot(waffle.mat,cellcolors=waffle.col,border=waffle.border,
>> show.values=TRUE,xat=10,yat=10,xlab="",ylab="")
>> axis(1,at=1:8,labels=seq(130,200,by=10))
>> axis(2,at=1:8)
>> axis.break(1)
>
> Being picky-picky-picky I would like to point out that Duncan's and
> David's functions don't *quite* reproduce the picture in the pdf file
> that the OP attached, when called with the data from that picture:
>
> egdat <- c(137,135,144,149,150,152,159,157,154,163,164,164,
> 161,162,165,164,179,173,173,182,180,185,180,197,190)
> myhist(egdat)
> boxhist(egdat)
>
> It's a matter of including the left or right endpoints in the bins.
>
> Duncan's function needs to swap "<" and "<=" in the definition of "keep"
> (and make a corresponding adjustment in the "|" clause, so as to look at
> the last rather than the first break value).
Well, that's just because the attached picture was wrong :-).
Duncan
>
> David's function needs to set "right=FALSE" in the call to cut().
>
> Jim's waffle plot gets it right, at the expense of needing to have the
> data organised in an inconvenient form.
>
> All that being said, all of you blokes came up with solutions that are
> far beyond my capability of producing. Hat's off to you.
>
> cheers,
>
> Rolf
>
More information about the R-help
mailing list