Code Monkey home page Code Monkey logo

plotflow's People

Contributors

mrdwab avatar mvkorpel avatar trinker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

plotflow's Issues

plotflow slow in linux

Tyler,

I love plotflow package. It has enabled me to do many PDF-relatd work for web scraping. One thing I am challenged with, however, is its speed on linux. I am running it on a Centos 7 server and it takes about 4-5 minutes what it would otherwise take 5-7 seconds on a Mac. Specs-wise, these two machines are not vastly different from each other.

I was wondering what the reason would be and how I can make it faster.

Thank you, again, Tyler, for your good work.

GGally suggestion

Really cool code, these are all functions that I remember coding several times in slightly different ways, always annoyed that I could not remember how I had done it the last time. Your package makes a good companion to the GGally package, a bit like scales helps ggplot2.

Ghostscript detection

It might be more tidy to change the line for Ghostscript detection in mergePDF.R to:

os <- names(which(sapply(testme, system, 
                         ignore.stderr = TRUE, ignore.stdout = TRUE) == 0))

The ignore.stderr and ignore.stdout arguments will suppress the output of the system command from being displayed in the R console.

Add nested_map

#' Nested Map
#' 
#' Generate a nested map that shows nested, hierarchical proportions of a whole.
#' 
#' @param x A vector of nested, decreasing values.
#' @param labels The labels atached to each element of \code{x}.
#' @param text_size The text size for the labels.
#' @export
#' @examples
#' nested_map(x = c(100, 94, 84, 55, 22, 14, 9))
nested_map <- function(x, labels = c(LETTERS[1:length(x)]), text_size = 2.25){

    if(any(diff(x) >= 0)) stop("Nested maps works for vectors of decreasing values.")

    dat <- get_measurements(x, labels)

    dat[['xmin']] <- dat[['s2']][1] - dat[['s2']]
    dat[['xmax']] <- dat[['s2']][1]

    dat[['ymin']] <- 0
    dat[['ymax']] <- dat[['s1']]
    dat[['text_x']] <- dat[['xmin']]
    dat[['text_y']] <- dat[['ymax']]

    ggplot2::ggplot(dat, ggplot2::aes_string(xmin = 'xmin', xmax = 'xmax', ymin = 'ymin', ymax = 'ymax')) +
        ggplot2::geom_rect(alpha=.05, size=.8, ggplot2::aes_string(fill='labels', color='labels')) +
        geom_text(aes_string(x='text_x', y='text_y', label='txt'), hjust=-.1, vjust=1.1, size = text_size) +
        ggplot2::theme_minimal() +
        ggplot2::theme(
            legend.position='none',
            axis.text = ggplot2::element_blank(),
            axis.title = ggplot2::element_blank(),
            panel.grid = ggplot2::element_blank()
        )
}


get_measurements <- function(x, labels){

    gr <- (1+sqrt(5))/2

    prop <- c(NA, x[-1]/x[-c(length(x))])
    of <- c("", paste0(" of ", x[-length(x)]))
    txt <- paste0(labels, ": ", x, of, c("", paste0(" (", pp(prop[-1]), ")")))
    s1 <- c(1, rep(NA, length(x) - 1))
    s2 <- c(1/gr, rep(NA, length(x) - 1))
    A <- c(x1[1]*x2[1], rep(NA, length(x) - 1))

    for (i in 2:length(x)){
        A[i] <- A[i-1]*prop[i]
        s2[i] <- sqrt(A[i]/gr)
        s1[i] <- A[i]/s2[i]  
    }

    data.frame(lablels=labels, x=x, s1=s1, s2=s2, A=A, txt=txt, prop=prop, stringsAsFactors = FALSE)
}

pp <- function(x){gsub("^0", "", paste0(round(100*x, 1), "%"))}

merge_PDF skips first plot unless code is run line-by-line

I just tried out plotflow and ran into a strange problem. Here's a reproducible example:

library(plotflow)
library(ggplot2)

dat = data.frame(x=1:10, y=rnorm(10))
p1=ggplot(dat, aes(x,y)) + geom_line()
p2=ggplot(dat, aes(x,y)) + geom_line()
p3=ggplot(dat, aes(x,y)) + geom_line()

## Plot heights, widths
widths = c(9, 8, 10)
heights = c(5, 11, 6)

merge_pdf(length(widths), file = "test.pdf", 
          widths = widths,
          heights = heights)

plot(p1)
plot(p2)
plot(p3)

If I run the code line by line (by typing Command - Return (I'm on a Mac) over and over again on my keyboard), it works fine. But if I run the code all at once (for example, by selecting Run Region - Run All in the RStudio Code menu), the first plot "slot" (Enter plot 1:) somehow fails to actually input the first plot and moves to Enter plot 2:. This results in an invalid page count error. I've pasted in the output below.

Any ideas on what's causing this or how to fix it? I'll post to Stack Overflow if this isn't already a known problem.

> merge_pdf(length(widths), file = "test.pdf", 
+           widths = widths,
+           heights = heights)
Enter plot 1:

Enter plot 2:
plot(p1)
Enter plot 3:
plot(p2)
   **** Warning:  Invalid Page count.
   No pages will be processed (FirstPage > LastPage).
   **** Warning:  Invalid Page count.

   **** This file had errors that were repaired or ignored.
   **** The file was produced by: 
   **** >>>> R 3.1.3 <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

error

when I use the ggfaxt in R version >3.1.3, I always got an wrong information:
Error in ggplot2.object$facet[1:2] : object of type 'environment' is not subsettable.
While in version 3.1.1, the ggfaxt can perform. What's wrong with this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.