我想要的函数只是为了编程时的方便。
但是,如果我想在最后一行之后添加一个层,我必须在最后一行附加一个“+”,如果我想再次删除该层,我还必须再次删除“+”:
ggplot(df, aes(x,y,...)) +
geom_X(...) + # after this line, I can easily add layers
... +
layer_Z(...) # to add a layer after here, I have to modify also this line
我正在搜索函数
ggidentity()
它只返回绘图本身,将其用作默认的最后一行,以便我可以轻松地添加更多行,如中所示
ggplot(df, aes(x,y,...)) +
geom_X(...) + # after this line, I can easily add layers
... +
layer_Z(...) + # now it's easy to add layers after this line
ggidentity() # this doesn't change anything in the plot
identity <- function(x) x
它与magrittr包配合良好(并改进了我在探索性数据分析中的工作流程),但与ggplot2配合不好。