How can I use a graphic imported with grImport as axis tick labels in ggplot2 (using grid functions)?

后端 未结 3 980
长发绾君心
长发绾君心 2020-12-03 05:50

I\'m hoping I can combine the spiffy importing and drawing powers of grImport with the awesome graphing power of ggplot2, but I simply don\'t under

3条回答
  •  我在风中等你
    2020-12-03 06:20

    For a single panel, it is fairly straight-forward to extract information from the x axis grob, and replace it with your own. I'm not sure how this could be extended cleanly to automatic, multi-panel axes.

    library(grid)
    library(ggplot2)
    
    p <- qplot(1:12, rnorm(12))
    grid.newpage()
    g <- ggplotGrob(p)
    grid.draw(g)
    g0 <- getGrob(g, gPath("axis.text.x"), grep=TRUE)
    grid.set(gPath("axis.text.x"),
             pointsGrob(x = g0$x, y=0*g0$x + unit(0.5,"npc"),
                        pch=19, gp=gpar(col=seq_along(g0$x)),
                        name = g0$name), grep = TRUE)
    

    screenshot

提交回复
热议问题