0

I have a dataset like below in dictionary format,

data={'a': [10, 11,12,5,4,3,1], 'b': [7, 18,5,11,9,2,0]} 

How we can make a scatter plot in python using rpy2? where x axis is the months and y axis are the mutiples of 5? we need to plot the graph with the above values where a and b are the data points

Months should be based on the length of each key i.e for the above data we have 7 months since we have 7 data points
user2286041
  • 43
  • 1
  • 7

1 Answers1

0

This is a pretty involved data structure, and it's not completely clear what you're looking to do in terms of plotting. Here are a few hints, but it'd be easiest to help you if you would post the code you've tried but hasn't worked.

The R plot function takes two vectors corresponding to the x-axis values (months, here), and y-axis values (frequencies?). You'll want to go through your graph_data dictionary and calculate the y-axis values you want to plot for each month, and then make a corresponding vector for x containing the month numbers. For example:

x = [1,2,3,4]
y = [0.7, 0.9, 0.2, 0.4]

To do the plotting from rpy2, you'll need to convert the lists to vectors like so:

from rpy2 import robjects
x_vector = robjects.IntVector(x)
y_vector = robjects.FloatVector(y)

Then do the plotting:

robjects.r.plot(x_vector, y_vector, xlab="month", ylab="freq", main="")
Noah
  • 21,451
  • 8
  • 63
  • 71