6

I have seen both usages, yet I don't know the difference between 2 in practical.

And, why

stat_vline(xintercept="mean", geom="vline") # this works

But

geom_vline(xintercept="mean", stat="vline") # this doesn't work

Does that mean after passing mean to a next layer which is vline in this case, the function becomes character? Is this behaviour general?

4

1 回答 1

8

你可能发现了一个错误。如果您(再次)指定美学映射,它将起作用:

p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
p + geom_vline(aes(x=wt, y=mpg), xintercept="mean", stat="vline")

典型的ggplot2文档有点稀疏,这使得很难判断这是否是故意的。

于 2013-09-13T16:03:32.840 回答