gpt4 book ai didi

r - R-geom_density()使用哪种算法,以及如何提取曲线的点/等式?

转载 作者:行者123 更新时间:2023-12-03 21:22:51 28 4
gpt4 key购买 nike

我想知道geom_density()到底在做什么,所以我证明了图的合理性,以及是否有任何方法可以提取为绘制的每条曲线生成的函数或点。

谢谢

最佳答案

键入get("compute_group", ggplot2::StatDensity)(或以前的get("calculate", ggplot2:::StatDensity))将为您提供用于计算密度的算法。 (从根本上讲,这是对density()的调用,默认为kernel="gaussian"。)

图中使用的点由print.ggplot()不可见地返回,因此您可以像这样访问它们:

library(ggplot2)
m <- ggplot(movies, aes(x = rating))
m <- m + geom_density()
p <- print(m)
head(p$data[[1]], 3)
# y x density scaled count PANEL group ymin ymax
# 1 0.0073761 1.0000 0.0073761 0.025917 433.63 1 1 0 0.0073761
# 2 0.0076527 1.0176 0.0076527 0.026888 449.88 1 1 0 0.0076527
# 3 0.0078726 1.0352 0.0078726 0.027661 462.81 1 1 0 0.0078726


## Just to show that those are the points you are after,
## extract and use them to create a lattice xyplot
library(gridExtra)
library(lattice)
mm <- xyplot(y ~x, data=p$data[[1]], type="l")

关于r - R-geom_density()使用哪种算法,以及如何提取曲线的点/等式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12394321/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com