How to use the variable from the python in rpy2?

First, make two lists from your database. Something like:

cursor = con.cursor()       
cursor.execute("SELECT * FROM traffic")

#Retrieves data from SQL
rows = cursor.fetchall()  

Month = list()
Traffic = list()

for row in rows:
    Month.append(row['Month'])          # guesswork - what does a row look like?

Then, now you have two python lists, you can make a plot thus:

>>> r.plot(Month,Traffic)

You maybe want lines:

>>> r.plot(Month,Traffic,type="l")

You maybe want nice labels:

>>> r.plot(Month,Traffic,type="l",xlab="Month",ylab="Traffic")

Leave a Comment