[R] barplot in hexagram layout

Jim Lemon jim at bitwrit.com.au
Tue Sep 13 10:29:06 CEST 2011


On 09/13/2011 03:08 AM, Schatzi wrote:
> I updated the code as follows:
> dev.new(width=2.5, height=3,mar=c(0,0,0,0))
> par(mfrow=c(5,1),mar=c(.5, .5, 1.5, .5), oma=c(.4, 0,.5, 0))
> barplot(c(1,1,1,1,1),col=c("white","white","red","white","white"), axes =
> FALSE,border=NA)
> barplot(c(1,1,1,1,1),col=c("orange","white","white","white","yellow"), axes
> = FALSE,border=NA)
> barplot(c(1,1,1,1,1),col=c("white","white","white","white","white"), axes =
> FALSE,border=NA)
> barplot(c(1,1,1,1,1),col=c("blue","white","white","white","green"), axes =
> FALSE,border=NA)
> barplot(c(1,1,1,1,1),col=c("white","white","brown","white","white"), axes =
> FALSE,border=NA)
>
> I added the middle plot to add a space between the two middle barplots. The
> problem is that it is a bit too large of a space (they are further apart
> than the other points). I tried adjusting different options - mar, mgp, omd
> - of par and the "height" option of barplot and none of them seemed to help.
> Do you have any ideas of how to make the invisible middle plot a bit shorter
> or the plots above and below the middle slightly closer?
>
Hi Adele,
If you just want six rectangles on a white field, it might be simpler to 
make a blank plot:

plot(0,xlim=c(-2,2),ylim=c(-2,2),type="n",axes=FALSE,xlab="",ylab="")

and then display some rectangles:

rect(c(-0.5,-2,-2,-0.5,1,1),c(-1.8,-1.2,0.2,0.8,0.2,-1.2),
  c(0.5,-1,-1,0.5,2,2),c(-0.8,-0.2,1.2,1.8,1.2,-0.2),
  col=c("brown","blue","orange","red","yellow","green"))

You can make it into a function that would display different heights in 
a "hexagonal" pattern.

Jim



More information about the R-help mailing list