1. rpy2
  2. rpy2
  3. rpy2
  4. Issues


Issue #401 invalid


Frank Ferraro
created an issue


I'm trying to create a correlation plot, using R's pairs (graphics.pairs). However, it is not being handled correctly. Specifically, it does not handle panel functions correctly (including setting them to NULL).


Python 2.7

rpy2 v2.8.5

Expected output

Using the panel.hist function from the pairs help page [1], the following R code produces the correct output (correct_pairs_in_R.png):

USJudgeRatings = data('USJudgeRatings')
pairs(USJudgeRatings, lower.panel = NULL, upper.panel=NULL, diag.panel=panel.hist)

Actual output

rpy2 doesn't reflect this (incorrect_pair_in_rpy2.png, using [2]):

import rpy2.robjects as robjects
datasets = importr('datasets')
judges = robjects.packages.data(datasets).fetch('USJudgeRatings')['USJudgeRatings']
graphics.pairs(judges, lower_panel=robjects.NULL, upper_panel=robjects.NULL, diag_panel=panel_hist)


panel.hist <- function(x, ...)
         usr <- par("usr"); on.exit(par(usr))
         par(usr = c(usr[1:2], 0, 1.5) )
         h <- hist(x, plot = FALSE)
         breaks <- h$breaks; nB <- length(breaks)
         y <- h$counts; y <- y/max(y)
         rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)

[2] panel_hist = robjects.r([1]), i.e., the wrapped version of [1]

Comments (2)

  1. Laurent Gautier

    This is because in R the function pairs is a generic with pretty much only an ellipsis as a list of arguments. Because of this importr cannot "translate" any name with "." to names with "_" (since there are no names).


    graphics.pairs(judges, **{'lower.panel':robjects.NULL,

    (explanations are in the doc).

  2. Log in to comment