2017-03-16 106 views
0

我正在繪製一系列針對時間的指標,並使用facet_grid功能分別在一個對象上繪製每週圖。face_grid和ggplot - 顏色/顏色參數錯誤

result_df

week metric_a time_stamp 
20 2567     2015-09-30 09:04:29 
21 3567     2015-10-03 17:36:39 
22 3455     2015-10-11 19:29:32 

p = ggplot(aes(x='time_stamp',y='metric_a'),data=result_df) + scale_x_date(labels = date_format("%H:%M")) + geom_line() + facet_grid('week',scales='free_x') 

enter image description here

我現在希望用color參數來說明周之間的變化。

p = ggplot(aes(x='time_stamp',y='metric_a',color="week"),data=result_df) + scale_x_date(labels = date_format("%H:%M")) + geom_line() + facet_grid('week',scales='free_x') 

然而,這將返回:

row, col = self.facets.facet_map[rowname] 

爲什麼這是對色彩的說法,而不是facet_grid爭論的一個問題?

+0

不知道你是如何從蟒蛇訪問GGPLOT2。這是使用Rpy2嗎? –

+0

@感謝Mike。有一個python庫 - 「http://ggplot.yhathq.com /' – LearningSlowly

回答

0

我深入挖掘錯誤軌跡,注意到有一個被埋沒的KeyError。我認爲發現this這表明你可以使用pd.categorical

工作需要編輯:

result_df.week = result_df.week.astype("category")