rpy2 plot problem
Question: I use rpy2-2.0.8, R-2.11.1, Python-2.6.2 on Windows XP.

When I run this script, output image is filled with text message. I suppose
this message is function definition of clusplot.

[test.py]

    
    
    #!/usr/bin/env python
    # -*- mode: python -*- -*- coding: utf-8 -*-
    
    import rpy2.robjects as ro
    r = ro.r
    
    # read from csv file
    dataf = r('read.csv("test.csv", header=T, row.names="name")')
    
    # k-means
    r.library('cluster')
    k = 2
    cluster = r.kmeans(r.cmdscale(r.dist(dataf)), k)
    
    # plot
    r.jpeg('output.jpg')
    r.clusplot(r.pam(dataf, k))
    r('dev.off()')
    

[test.csv]

    
    
    name,a,b,c,d,e,f,g,e,h,I,j,k
    x1,1421,99.4,19.5,241.4,103.7,18.8,13.4,4.8,76.3,535.6,28.6,10.3
    x2,1495,97.8,22.5,263.3,160.3,9.1,13.7,4.3,93.8,568,33.3,10.4
    x3,2649,95.8,14.6,198.6,94.6,15.9,11.6,11.7,85,521.5,52.7,8.71
    x4,3251,100.2,27.5,240.9,121,28,13.3,18.9,99.1,336.1,5.1,3.03
    x5,2705,100.3,15.3,157.1,95.3,23.4,7.5,17,87.9,366.8,12.1,3.59
    x6,3157,100.3,12.4,164,97.1,10.2,8.8,17.4,98.4,418.5,24.2,4.45
    x7,2045,104.4,25.3,246.3,131,16.6,14,19.1,96.9,584.2,7.8,6.73
    x8,2228,99.1,21.7,246.9,112.2,23.3,15.1,5.3,88.4,415.5,54.2,4.03
    x9,2037,100.1,30,296.6,150.7,31.5,15.4,17.8,93.1,346.8,6.1,3.47
    x10,2336,99.7,17.6,210.8,116.5,21.5,12.6,10.1,69.9,411,63.9,16.5
    x11,1264,101.8,29.3,256.1,126.2,14.3,14.8,5.4,94,540.1,28.5,7.46
    x12,1566,98.8,23.7,285.3,128.6,15.1,15.5,8.5,91.5,549.3,59.2,10.5
    x13,2210,98.8,28.3,234.4,143.2,17.3,12.7,11.2,95.6,492.1,53.5,8.6
    

But I use R console (not rpy2), No text overwapping problem.

Does anyone help me?


Answer: I have solved this problem by myself.

R plot command completes the plot title automatically when it is not given. R
command with console and via rpy2 have different behavior for this complement.
(I think it is a kind of bug for rpy2)

So set the title with "main" argument explicitly like this.

    
    
    # plot
    r.jpeg('output.jpg')
    r.clusplot(r.pam(dataf, k), main="result")
    r('dev.off()')
    

