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

后端 未结 3 970
长发绾君心
长发绾君心 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:27

    here is an example:

    # convert ps to RGML
    PostScriptTrace(file.path(system.file(package = "grImport"), "doc", "GNU.ps"), "GNU.xml")
    PostScriptTrace(file.path(system.file(package = "grImport"), "doc", "tiger.ps"), "tiger.xml")
    # read xml
    pics <- list(a = readPicture("GNU.xml"), b = readPicture("tiger.xml"))
    
    # custom function for x axis label.
    my_axis <- function () {
      structure(
          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")), 1:2) + opts( axis.text.x = my_axis())
    

    enter image description here

提交回复
热议问题