当我尝试使用%+%
运算符来重新绘制新数据的现有绘图时,我遇到了一个障碍。我的代码如下所示: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