views:

58

answers:

1

I need to draw many different tile plots, which have squares and dots on top of the tiles according to data. Unfortunately I cannot include illustrating picture, but basically the plot consist of tiles which either have squares and dots on them or not.

Each of those figures has different number of tiles on x-direction and y-direction. As a result, I cannot use absolute units (mm) to scale the dot sizes and box sizes. Is there any way to specify the size of the dot in relative terms. For instance, like geom_point(aes(x=x, y=y), size = 0.5 * tile_size()).

The following buggy code snippet

df <- data.frame(x=factor(c(1:4), labels=c("a", "b", "c", "d")), y=factor(c(1:4), labels=c("f", "g", "h", "j")))
p <- ggplot(data = df) + geom_tile(aes(x=x, y=y), fill="green", color="black")
p <- p + opts(aspect.ratio=2)
p <- p + geom_point(aes(x=x, y=y), color="red", size = 4, shape=15, color="red")
p <- p + geom_point(aes(x=x, y=y), color="blue", size = 2)
p <- p + scale_x_discrete("Variables") + scale_y_discrete("Time")
show(p)

almost achieves the desired functionality, except if I resize the graphical window or the pdf dimensions, the relative size of points and boxes with respect to the tile sizes changes. In particular, the dots and boxes might be larger than the tile they are drawn on, which is absolute no-no.

If relative scaling of point size is impossible, then I would like to know is it possible to specify the dimensions of the plot area (plot without axes labels, ticks and so on) using ggsave() or pdf(). Then I could do relative scaling by myself.

A: 

I think you want to specify sizes in data units, rather than physical units. This is something that is a little tricky for circles and squares because they may actually be ovals and rectangles in data space (unless you are using coord_equal). But if you want to do this, you can generate the glyphs yourself and use geom_polygon to draw them.

hadley