當我嘗試使用%+%
運算符來重新繪製新數據的現有繪圖時,我遇到了一個障礙。我的代碼如下所示:ggplot2:使用%+%繪製新數據
df <- data.frame(ending=now()+hours(0:5), actual=runif(6), pred=runif(6))
p <- ggplot(df, aes(x=ending)) +
geom_line(aes(y=actual, color='Actual')) +
geom_line(aes(y=pred, color='Predicted')) +
ylab('Faults') +
scale_color_manual('Values', c("Predicted"="red", "Actual"="black"))
p
工作正常。但是,當我嘗試更換新df
,我打的錯誤:
p1 %+% df
Error in bl1$get_call : $ operator is invalid for atomic vectors
有什麼想法?
盡我所能想出是'GGPLOT2 :: \'%+%\'(P,DF )',但我不知道如何組合指定中綴二進制運算符和名稱空間限定。 – 2012-03-09 23:55:24
啊哈 - 我試過'\'ggplot2 ::%+%\''但那不起作用。 – 2012-03-10 03:18:11
可以插入二元運算符的方法嗎?這可能有助於解決命名空間碰撞,也許可能。 – 2012-03-10 03:19:28