unwanted text displayed in plot

Issue #318 invalid
Edouard Goudenhoofdt created an issue

I got unwanted function code text in a plot when running this code:

from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import FloatVector
extremes = importr("extRemes")
import numpy as np
x = FloatVector(np.array([5.07,8.48,7.63,5.75,8.43,5.61,10.64,6.61,8.53,7.58,7.75,5.03,5.47,5.55]))
fit = extremes.fevd(x, threshold=5, span=10)
extremes.plot_fevd(fit,'qq')

rpy2graphicbug.png

Note that the image does not correspond to the code since I got error when using grdevices.pdf interatively.

Comments (10)

  1. Laurent Gautier

    This is not a bug, but a feature in R.

    Several plot functions use the expression in their call to make labels. The issue with that is that anonymous variables sent by rpy2 can be rather long expressions. A workaround is to create R variable names instead of anonymous functions.

  2. Edouard Goudenhoofdt reporter

    Hi Laurent,

    Thank you for the quick reply. I see now that the function is used to make the plot title. Sorry I don't understand your workaround. My workaround for this particular case is to use the option "main" in the plot. Still I consider this as a bug in rpy2 since it can't reproduce R output. Can't you implement your workaround which seems general?

    BR,

    Edouard

  3. Laurent Gautier

    This is arguably not a bug.

    Here what is happening is that you are passing an rpy2 object, which is an anonymous data structure as far as the R function called is concerned.

    That's pretty much the same when you do in R:

    plot(c(1,2,3))
    

    The R documentation about deparse() is worth a read, as this is almost certainly the one used by the plotting function you are calling.

  4. Laurent Gautier

    Not a bug, but a question about usage (StackOverflow is a better place than here).

    You may be able to find your way to an answer from this:

    from rpy2.robjects.packages import importr
    from rpy2.robjects import globalenv
    from rpy2.robjects.vectors import IntVector
    x=IntVector((1,2,3))
    globalenv['x']=x
    base=importr("base")
    graphics=importr("graphics")
    # should print a "x" on the y-axis
    graphics.plot.rcall((("x", base.as_name("x")),), globalenv)
    
  5. Log in to comment