[英]How to calculate 1-CDF in R and plot it?
I want to plot the 1-CDF in R我想要 plot R 中的 1-CDF
I am using the ggplot stat_ecdf我正在使用 ggplot stat_ecdf
g1=ggplot() +
stat_ecdf(data=data_ploting, aes(x, colour=ggg), alpha=0.8, geom= "smooth", pad = FALSE) +
theme_test ()
The base R function ecdf
returns a function that you can use in new expressions, including subtracting it from one.基数 R function
ecdf
返回一个 function,您可以在新表达式中使用它,包括从一个表达式中减去它。 You can therefore also use the usual methods for plotting $1-F(x)$.因此,您也可以使用常用方法绘制 $1-F(x)$。 Example:
例子:
x <- sort(iris$Sepal.Length)
cdf <- ecdf(x)
plot(x, 1 - cdf(x), type="s")
The ?stat_ecdf
help page shows that there is a "Computed variable" y
which holds the calculated CDF value. ?stat_ecdf
帮助页面显示有一个“计算变量” y
保存计算的 CDF 值。 You can get at that value using stat()
and then transform it however you like.您可以使用
stat()
获取该值,然后根据需要对其进行转换。 So, for example, this should work因此,例如,这应该有效
ggplot(data_ploting) +
aes(x = x, y = 1-stat(y), colour=ggg) +
stat_ecdf(alpha=0.8, geom = "smooth", pad = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.