ggplot2 plots not rendering points if alpha in geom_points is set to other value than 1 in anaconda
<p>I am trying to use R through Anaconda python. rpy2 is installed. The problem I am running into is when I set alpha to a value other than 1 in geom_point the points do not show in the plot but will show if alpha is set to 1. Am I missing something? Here is the code that I am running (Ubuntu16.04):</p>

<pre><code>from rpy2 import robjects
from rpy2.robjects.packages import importr
import rpy2.robjects.lib.ggplot2 as ggplot2
from rpy2.robjects.packages import importr
base = importr('base')

#mtcars = datasets.__rdata__.fetch('mtcars')['mtcars']

rnorm = stats.rnorm
dataf_rnorm = robjects.DataFrame({'value': rnorm(300, mean=0) + rnorm(100, mean=3),
                                  'other_value': rnorm(300, mean=0) + rnorm(100, mean=3),
                                  'mean': IntVector([0, ]*300 + [3, ] * 100)})


gp = ggplot2.ggplot(dataf_rnorm)

pp = gp + \
     ggplot2.aes_string(x='value', y='other_value') + \
     ggplot2.geom_point(alpha = 1) + \
     ggplot2.geom_density2d(ggplot2.aes_string(col = '..level..')) + \
     ggplot2.ggtitle('point + density')
pp.plot()
</code></pre>

<p>Thanks for any insight.</p>

<p><a href="http://i.stack.imgur.com/qvd9N.png" rel="nofollow">alpha set to 0.4</a></p>

<p><a href="http://i.stack.imgur.com/JNRDl.png" rel="nofollow">alpha set to 1</a></p>

<p>I still haven't managed to get ggplot2 to render correctly on the display ( I am not sure if this is a bug in rpy2 or something else). However, I can get ggplot2 to render correctly to file in this case png--I also tested tiff but not pdf or ps. Below is the code. Matplotlib opens the file, reads the image and displays it (this allows me to see the image that is written rather than opening it with an image viewer).</p>

<pre><code>from rpy2 import robjects
from rpy2.robjects.packages import importr
import rpy2.robjects.lib.ggplot2 as ggplot2
from rpy2.robjects.packages import importr
from rpy2.robjects import Formula, Environment
from rpy2.robjects.vectors import IntVector, FloatVector
from rpy2.robjects.lib import grid

base = importr('base')

rprint = robjects.globalenv.get("print")
stats = importr('stats')
lattice = importr('lattice')
datasets = importr('datasets')
mtcars = datasets.__rdata__.fetch('mtcars')['mtcars']


rnorm = stats.rnorm
dataf_rnorm = robjects.DataFrame({'value': rnorm(300, mean=0) + rnorm(100, mean=3),
                              'other_value': rnorm(300, mean=0) + rnorm(100, mean=3),
                              'mean': IntVector([0, ]*300 + [3, ] * 100)})


 gp = ggplot2.ggplot(dataf_rnorm)

 pp = gp +\
    ggplot2.aes_string(x='value', y='other_value') +\
    ggplot2.geom_point(alpha = 0.4) +\
    ggplot2.geom_density2d(ggplot2.aes_string(col = '..level..')) + \
    ggplot2.ggtitle('point + density')

from rpy2.robjects.lib import grdevices
cairo = importr("Cairo")
cairo.Cairo(600, 600, file="test.png", type="png", bg="white" )
pp.plot()
grdevices.dev_off()
#%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

img = mpimg.imread("test.png")
plt.imshow(img)
plt.show()
</code></pre>

python anaconda