[R] purrr::pmap does not work

MacQueen, Don macqueen1 at llnl.gov
Thu Jun 8 00:12:24 CEST 2017


You might try
   matplot()

example:
x <- matrix(rnorm(30), ncol=3)

## plot a dependent variable (1:10) against a bunch of independent variables (the three columns of x)
matplot(x , 1:10, type='b')

## or a bunch of dependent variables (the three columns of x) against an independent variable (1:10)
matplot(1:10,  x, type='b')

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


On 6/7/17, 7:34 AM, "R-help on behalf of G.Maubach at weinwolf.de" <r-help-bounces at r-project.org on behalf of G.Maubach at weinwolf.de> wrote:

    Hi All,
    
    I try to do a scatterplot for a bunch of variables. I plot a dependent 
    variable against a bunch of independent variables:
    
    -- cut --
    graphics::plot(
      v01_r01 ~ v08_01_up11,
      data = dataset,
      xlab = "Dependent",
      ylab = "Independent #1"
    )
    
    -- cut --
    
    It is tedious to repeat the statement for all independent variables. Found 
    an alternative, i.e. :
    
    -- cut --
    
    mu <- list(5, 10, -3)
    sigma <- list(1, 5, 10)
    n <- list(1, 3, 5)
    fargs <- list(mean = mu, sd = sigma, n = n)
    fargs %>%
      purrr::pmap(rnorm) %>%
      str()
    
    -- cut --
    
    I tried to use this for may scatterplot task:
    
    -- cut --
    
    var_battery$v08 <- paste0("v08_", formatC(1:8, width = 2, format = "d", 
    flag = "0"))
    v08_var_labs <- paste0("Label_", 1:8)
    
    dataset <- as.data.frame(
      matrix(
        data = sample(
          x = 1:11,
          size = 90,
          replace = TRUE),
        nrow = 10,
        ncol = 9))
    names(dataset) <- c("v01_r01", var_battery$v08)
    
    independent <- as.list(dataset$v01_r01)
    dependent <- as.list(dataset[var_battery$v08])
    
    fargs <- list(
      x = independent,
      y = dependent,
      ylab = v08_var_labs)
    
    fargs %>% 
      purrr::pmap(
        function(d = dataset, xvalue = x, yvalue = y,
                 xlab = "Label for x variable",
                 ylab = ylab) {
          graphics::plot(
            xvalue ~ yvalue,
            data = d,
            xlab = xlab,
            ylab = ylab)
        }
      )
    
    -- cut --
    
    The last statement comes back with
    
    Error: Element 2 has length 8, not 1 or 10.
    
    How can I get it up n running? Do you suggest a better solution for the 
    task described?
    
    Kind regards
    
    Georg
    
    ______________________________________________
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
    



More information about the R-help mailing list