A proof-of-principle is given in the ggExtra package,
require(gridExtra)
require(ggExtra)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
str(dsmall)
d <- ggplot(dsmall, aes(carat, price)) +
annotate("table", x=1, y=10000, table=head(iris[, 1:3], 3)) +
geom_point()
d
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
>
To change the size you can use the global gpar() of the tableGrob,
annotate("table", x=1, y=Inf, table=head(iris[, 1:3], 3), gp=gpar(cex=0.5))
and/or play with the individual components such as cell margins and
header text size etc. See the complete list of arguments in
?tableGrob.
I'm not sure why but the previous example fails for me with y=Inf. In
any case, the placement is relative to the center of the table (I
think), and I have not really thought of a way to specify hjust/vjust.
Since the table grob knows its actual size, in theory it should be
possible to use this information in an improved ggplot2 geom.
HTH,
baptiste
GeomTable <- proto(Geom, {
objname <- "table"
desc <- "Custom table grob"
draw <- function(., data, scales, coordinates, table,
just=c("centre", "centre"), ...) {
with(coordinates$transform(data, scales), {
g <- tableGrob(table, ...)
width <- grobWidth(g)
height <- grobHeight(g)
g <- editGrob(g, vp=viewport(x = x, y = y, width=width,
height=height, just = just))
ggname(.$my_name(), g)
})
}
required_aes <- c("x", "y")
default_aes <- function(.)
aes(x=0.5, y=0.5)
default_stat <- function(.) StatIdentity
guide_geom <- function(.) "table"
draw_legend <- function(., data, ...) { }
icon <- function(.) { }
examples <- function() {#
require(gridExtra)
require(ggExtra)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
d <- ggplot(dsmall, aes(carat, price)) +
annotate("table", x=1, y=10000, table=head(iris[, 1:3], 3),
just=c("right","top")) +
geom_point()
d
}
})
geom_table <- GeomTable$build_accessor()
baptiste
On Sun, Jul 11, 2010 at 11:51 PM, Felipe Carrillo