title: Using R in Python with Rpy2: how to ggplot2?
body: <p>I am trying to use R in Python and I found Rpy2 very interesting. It is powerful and not that difficult to use, however even if I have read the documentation and looked for a similar question, I wasn't able to solve my problem with the ggplot2 library.</p>
  <p>Basically I have a dataset with 2 columns, 11 rows and no header and I would like to do a scatter plot using this R code from Python:</p>
  <pre><code>ggplot(dataset,aes(dataset$V1, dataset$V2))+geom_point()+scale_color_gradient(low=&quot;yellow&quot;,high=&quot;red&quot;)+geom_smooth(method='auto')+labs(title = &quot;Features distribution on Scaffolds&quot;, x='Scaffolds Length', y='Number of Features')
  </code></pre>
  <p>I have tested this code in R (after read.table my file) and it works. Now, this is my python script:</p>
  <pre><code>import math, datetime
  import rpy2
  import rpy2.robjects as robjects
  import rpy2.robjects.lib.ggplot2 as ggplot2
  
  r = robjects.r
  df = r(&quot;read.table('file_name.txt',sep='\t', header=F)&quot;)
  gp = ggplot2.ggplot(df, ggplot2.aes(df[0], df[1])) + ggplot2.geom_point() + ggplot2.scale_color_gradient(low=&quot;yellow&quot;,high=&quot;red&quot;) + ggplot2.geom_smooth(method='auto') + ggplot2.labs(title = &quot;Features distribution on Scaffolds&quot;, x='Scaffolds Length', y='Number of Features')
  gp.plot()
  </code></pre>
  <p>If i run this Python code, it gives me two errors. The first is:</p>
  <pre><code>gp = ggplot2.ggplot(df, ggplot2.aes(df[0], df[1]))
  TypeError: new() takes exactly 1 argument (3 given)
  </code></pre>
  <p>and the second is:</p>
  <pre><code>AttributeError: 'module' object has no attribute 'scale_color_gradient'
  </code></pre>
  <p>Can someone help me to understand where I'm wrong please?</p>