2012-10-24 20 views
0

我有以下簡單的代碼,試圖在同一個圖中顯示三個圖。我要求的「線條」功能的最後兩張圖不會顯示出來,而我正處於智慧結局之中。這是一個錯誤還是我在做一些愚蠢的事情?用幾行繪製圖形rpython2 - 其他行不會顯示

解決方法,或者不使用「行」的方法,也讚賞。

沒有錯誤消息,但不會顯示我要求的行(請參閱下面的r.lines()調用)。

from rpy2.robjects import r 
from rpy2.robjects.packages import importr 
grdevices = importr('grDevices') 

d = {0: {0: 5669, 800: 1001, 100: 2240, 200: 1606, 300: 1366, 400: 1236, 500: 1146, 600: 1083, 900: 964, 700: 1037}, 10: {0: 0, 800: 155, 100: 229, 200: 218, 300: 194, 400: 178, 500: 171, 600: 165, 900: 150, 700: 160}, 5: {0: 0, 800: 195, 100: 415, 200: 330, 300: 279, 400: 258, 500: 241, 600: 219, 900: 185, 700: 201}} 
x = range(0,1000,100) 
y = [d[0][i] for i in x] 
z = [d[5][i] for i in x] 
ae = [d[10][i] for i in x] 

#grdevices.pdf(file = 'reads_per_slackvalue_and_cluster_size.pdf') 

r.plot(x,y, main='Reads per slack value', xlab='slack value',ylab='number of reads', type='l', col='blue') 
r.lines(x, z, col='red') 
r.lines(x, ae, col='green') 

#r.legend("topleft", ['0','5','10'], ['blue','red','green']) 

#grdevices.dev_off() 

show_image = raw_input() 

這是結果:

enter image description here

這是我所得到的交互方式做同樣的東西,在R(更正確):

enter image description here

+0

http://rpy.sourceforge.net/rpy2/doc-2.2/html/graphics.html#package-ggplot2 – Konstant

回答

1

確定關於你的rpy2代碼?兩個提示:

  1. rpy2生成的圖和R圖顯示相當不同的曲線形狀。可能是要調查的東西?

  2. 下面兩行添加到您的代碼確實做了第二行。絕對值得檢查你的x和y座標是的繪圖區域內。

代碼:

from rpy2.robjects.vectors import IntVector 
r.lines(x, IntVector(y) - 500, col = "green") 
+0

會考慮明天,但這些都是很大的提示。 –