Sha256: 045ebf9583fa05a886ae4173f2bd95e6a29c2ec97aad016e08930de77fb1bd49

Contents?: true

Size: 1.48 KB

Versions: 280

Compression:

Stored size: 1.48 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_light();
        if (length(plot$theme$text) == 0) plot <- plot + theme(text = element_text(size=base.size));

        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

280 entries across 280 versions & 1 rubygems

Version Path
rbbt-util-5.34.1 share/Rlib/svg.R
rbbt-util-5.34.0 share/Rlib/svg.R
rbbt-util-5.33.21 share/Rlib/svg.R
rbbt-util-5.33.20 share/Rlib/svg.R
rbbt-util-5.33.19 share/Rlib/svg.R
rbbt-util-5.33.18 share/Rlib/svg.R
rbbt-util-5.33.17 share/Rlib/svg.R
rbbt-util-5.33.16 share/Rlib/svg.R
rbbt-util-5.33.15 share/Rlib/svg.R
rbbt-util-5.33.14 share/Rlib/svg.R
rbbt-util-5.33.13 share/Rlib/svg.R
rbbt-util-5.33.12 share/Rlib/svg.R
rbbt-util-5.33.11 share/Rlib/svg.R
rbbt-util-5.33.9 share/Rlib/svg.R
rbbt-util-5.33.8 share/Rlib/svg.R
rbbt-util-5.33.7 share/Rlib/svg.R
rbbt-util-5.33.6 share/Rlib/svg.R
rbbt-util-5.33.5 share/Rlib/svg.R
rbbt-util-5.33.4 share/Rlib/svg.R
rbbt-util-5.33.3 share/Rlib/svg.R