gpt4 book ai didi

R ecdf 折线图上的高亮点

转载 作者:行者123 更新时间:2023-12-05 00:13:09 24 4
gpt4 key购买 nike

我正在使用 ggplot 和 stat_ecdf 函数创建频率图。我想将 Y 值添加到特定 X 值的图表中,但就是不知道怎么做。 geom_point 或 geom_text 似乎是可能的选项,但由于 stat_ecdf 自动计算 Y,我不知道如何在 geom_point/text 映射中调用该值。

我的初始情节的示例代码是:

x = as.data.frame(rnorm(100))
ggplot(x, aes(x)) +
stat_ecdf()

现在我将如何在这里添加特定的 y-x 点,例如x = -1 处的 y 值。

最佳答案

最简单的方法是使用 ecdf() 预先创建 ecdf 函数。来自 stats包,然后使用 geom_label() 绘制它.

library(ggplot2)
# create a data.frame with column name
x = data.frame(col1 = rnorm(100))
# create ecdf function
e = ecdf(x$col1)

# plot the result
ggplot(x, aes(col1)) +
stat_ecdf() +
geom_label(aes(x = -1, y = e(-1)),
label = e(-1))

enter image description here

关于R ecdf 折线图上的高亮点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48988768/

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