0

我发现自己经常想命名一个情节并显示它。所以我可能会做类似的事情

require(ggplot2)
myplot <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point() # store the plot
myplot # view the plot

有没有一种更优雅的方式可以在一行中显示和查看绘图?myplot <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point(); myplot比我的意思更优雅。

有时我也会这样做:

ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point()
myplot <- last_plot()

但这并没有更好。

4

1 回答 1

4

您可以使用括号来打印表达式的输出,如果用于此目的,我听说它被称为“printheses”。

library(ggplot2)

(myplot <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point())

reprex 包于 2021-07-07 创建(v1.0.0)

于 2021-07-07T18:54:14.620 回答