Sha256: 082bdc2c4877361043595165b7cdc383a06438443bf10455e4f26ceff91c005d

Contents?: true

Size: 1.37 KB

Versions: 17

Compression:

Stored size: 1.37 KB

Contents

rbbt.require('plyr')
rbbt.require('proto')
rbbt.require('ggplot2')
rbbt.require('gridSVG')
rbbt.require('grid')
rbbt.require('XML')
rbbt.require('ggthemes')
rbbt.require('Cairo')

# Modified from http://aaronecay.com/blog/2014/02/tooltips-in-ggplot/

rbbt.SVG.extract <- function(plot, size=NULL, prefix=NULL, ...){

    if (is.null(prefix)) prefix = rbbt.random_string();
    if (is.null(size)){
        print(plot, type='cairo');
        mysvg <- grid.export(prefix=prefix, ...)
    }else{
        base.size = 10 * (7/size)
        resolution = 72 * (size/7)

        if (length(plot$theme) == 0) plot <- plot + theme_gdocs();

        plot$theme$text$size = base.size

        print(plot, type='cairo')

        mysvg <- grid.export(res=resolution, prefix=prefix, ...)
    }

    xml <- saveXML(mysvg$svg)
    xml
}

rbbt.SVG.save <- function(filename, plot, width=NULL, height=NULL){
    if (is.null(width)){
        if (is.null(height)){
            size = NULL
        }else{
            size=height
        }
    }else{
        if (is.null(height)){
            size = width
        }else{
            size=max(width, height)
        }
    }

    xml = rbbt.SVG.extract(plot, size)
    fileConn<-file(filename, 'w')
    cat(xml, file=fileConn)
    close(fileConn)
}

rbbt.SVG.save.fast <- function(filename, plot, width=3, height=3){
    ggsave(file=filename, plot, width=width, height=height);
}

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rbbt-util-5.21.115 share/Rlib/svg.R
rbbt-util-5.21.114 share/Rlib/svg.R
rbbt-util-5.21.113 share/Rlib/svg.R
rbbt-util-5.21.112 share/Rlib/svg.R
rbbt-util-5.21.111 share/Rlib/svg.R
rbbt-util-5.21.110 share/Rlib/svg.R
rbbt-util-5.21.109 share/Rlib/svg.R
rbbt-util-5.21.107 share/Rlib/svg.R
rbbt-util-5.21.106 share/Rlib/svg.R
rbbt-util-5.21.104 share/Rlib/svg.R
rbbt-util-5.21.103 share/Rlib/svg.R
rbbt-util-5.21.102 share/Rlib/svg.R
rbbt-util-5.21.101 share/Rlib/svg.R
rbbt-util-5.21.100 share/Rlib/svg.R
rbbt-util-5.21.99 share/Rlib/svg.R
rbbt-util-5.21.98 share/Rlib/svg.R
rbbt-util-5.21.97 share/Rlib/svg.R