所以我的示例数据是:
x <- runif(1000, min = 0, max = 5)
y <- (2 / pi) * atan(x)
z <- floor(x)
df <- data.frame(x, y, z)
我画出x的箱线图,并由z合并:
library(ggplot2)
g <- ggplot(df, aes(x = x, y = y, group = z)) +
geom_boxplot()
g
但事实是,在我的实际数据中,我不确定y值是否遵循(2 / pi) * atan(x)
。那里有一个随机元素。因此,如何在图形上方绘制函数以自己查看?根据ggplot2文档,我尝试过...
g + stat_function(fun = (2 / pi) * atan(x), colour = "red")
...但是收到错误消息Warning message: Computation failed in 'stat_function()': 'what' must be a function or character string
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句