Drawing rectangles in plot area

55 views
Skip to first unread message

Bogaso

unread,
Aug 19, 2010, 10:44:28 AM8/19/10
to ggplot2
Hi friends, I would like to create following plot, uploaded here:
http://www.2shared.com/photo/jy7p7-0U/plot.html

Here I wanted to create four equally sized rectangles to cover the
entire plot area with different colors. However there should not be
any unused area (unlike that plot in example) in between any
boundaries.

There must be some way out to create the same using ggplot2. I would
be really grateful if someone point me how to do that.

Thanks,

baptiste Auguié

unread,
Aug 19, 2010, 10:56:39 AM8/19/10
to Bogaso, ggplot2
Do you need to use ggplot2 for this?

library(grid)

windowGrob = function(colours, gp = gpar(), vp=NULL, draw=TRUE, ...) {

fillm = matrix(colours, ncol= n2mfrow(length(colours))[2] )

g = rasterGrob(fillm, x = unit(0.5, "npc"), y = unit(0.5,
"npc"), width = unit(1, "npc"), height = unit(1,
"npc"),..., interpolate=FALSE,
gp = gp, vp = vp)

if (draw) grid.draw(g)
invisible(g)
}

windowGrob(palette()[1:4])


HTH,

baptiste

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Bogaso

unread,
Aug 19, 2010, 11:00:45 AM8/19/10
to ggplot2
Thanks baptiste for your help. This is what I wanted. However I need
to use ggplot because there are some other additions would come on top
of that, for which I prefer to use ggplot as it looks prettier and
more professional for my presentation purpose.

Really helpful if somebody points me how to do using ggplot.

baptiste Auguié

unread,
Aug 19, 2010, 11:12:17 AM8/19/10
to Bogaso, ggplot2
You can do it with geom_tile,


d = expand.grid(x = 1:2, y = 1:2)
d$fill = seq(1, nrow(d))

qplot(x,y, data=d,fill=fill, geom="tile")

HTH,

baptiste
Reply all
Reply to author
Forward
0 new messages