The function absoluteGrob {ggplot2}
shows a behavior that I am not able to debug. I have ggplot2
installed and I can see the help page by ?absoluteGrob
.
However, R does not find it when I try to use it:
> absoluteGrob
Error: object 'absoluteGrob' not found
More particularly, I try to execute the following code (from this answer to plot some graphs as x-labels):
library(grid)
library(ggplot2)
library(grImport)
library(igraph)
npoints <- 3
y <- rexp(npoints)
x <- seq(npoints)
pics <- vector(mode="list", length=npoints)
for(i in 1:npoints){
fileps <- paste0("motif",i,".ps")
filexml <- paste0("motif",i,".xml")
# Postscript file
postscript(file = fileps, fonts=c("serif", "Palatino"))
plot(graph.ring(i), vertex.label.family="serif", edge.label.family="Palatino")
dev.off()
# Convert to xml accessible for symbolsGrob (my_axis)
PostScriptTrace(fileps, filexml)
pics[i] <- readPicture(filexml)
}
my_axis <- function () {
function(label, x = 0.5, y = 0.5, ...) {
absoluteGrob(
do.call("gList", mapply(symbolsGrob, pics[label], x, y, SIMPLIFY = FALSE)),
height = unit(1.5, "cm")
)
}
}
qplot(factor(c("a", "b", "c")), 1:npoints) + scale_x_discrete(labels= my_axis())
But I get the error:
Error in scale$labels(breaks) : could not find function "absoluteGrob"
Any help (or alternatives) is welcome.
ggplot2 version:
ggplot2_1.0.1
Edit
Even in the simple case...
It does not work:
library(ggplot2)
absoluteGrob
It does:
library(ggplot2)
ggplot2:::absoluteGrob