geom_histogram(aes(x, ..density..), binwidth = 1, colour = "black", fill = "white") + stat_function(geom = "line", fun = plot_mix_comps, args = list(c1[1], c1[2], lam[1]/sum(lam)), stat_function(geom = "line", fun = plot_mix_comps, args = list(c2[1], c2[2]...
stat_qq()#or geom_qq() 自定义统计变换函数 可通过stat_function自定义一些统计变换函数来绘图,如正弦曲线、正态分布曲线等。 a <- ggplot(data.frame(x=c(-5,5)),aes(x))+ stat_function(fun=dnorm) #传入的函数只需名字,无需括号b <- ggplot(data.frame(x=c(-5,5)),aes(x))+ stat_functio...
首先我们构造一个统计量stat来衡量预测值与期望值的偏差: 下面用R语言计算该统计量: > abline(v = quantile(S0, 0.95), col ="red") > stat = function(obsvd, exptd = 20 * pvec) { #写函数计算stat + sum((obsvd -exptd)^2 / exptd) + } > stat(obsunder0[, 1]) #计算第一列的stat...
偏度和峰度: 为了计算偏度和峰度我们能够自己实现函数stat例如以下: stat <- function(x,na.omit=F){ if(na.omit) x <- x[!is.na(x)] m<- mean(x) n<- length(x) s<- sd(x) skew <- sum((x-m)^3/s^3)/n kurt <- sum((x-m)^4/s^4)/n - 3 return(c(n=round(n),mean=m,...
stat_qq() #or geom_qq() image.png 自定义统计变换函数 可通过stat_function自定义一些统计变换函数来绘图,如正弦曲线、正态分布曲线等。 a<-ggplot(data.frame(x=c(-5,5)),aes(x))+stat_function(fun=dnorm)#传入的函数只需名字,无需括号
"stat_function""stat_identity"[16]"stat_qq""stat_qq_line""stat_quantile""stat_sf""stat_sf_coordinates"[21]"stat_smooth""stat_spoke""stat_sum""stat_summary""stat_summary_2d"[26]"stat_summary_bin""stat_summary_hex""stat_summary2d""stat_unique""stat_ydensity"[31]"update_stat_...
> ls("package:ggplot2",pattern="stat_.+") [1] "stat_bin" "stat_bin_2d" "stat_bin_hex" "stat_bin2d" "stat_binhex" [6] "stat_boxplot" "stat_contour" "stat_count" "stat_density" "stat_density_2d" [11] "stat_density2d" "stat_ecdf" "stat_ellipse" "stat_function" "stat_id...
> library(dplyr)> library(ggplot2)> tibble(x = rbinom(10000, size=100, prob=0.2))%>%+ ggplot(aes(x= x))++ geom_histogram(aes(y=..density..))++ stat_function(+ fun =dnorm,+ args =list(mean = 20, sd = 4),+ color ="red"+ ) ...
stat_density2d 绘制二维密度图 stat_function 添加函数曲线 stat_hline 添加水平线 stat_identity 绘制原始数据,不进行统计变换 stat_qq 绘制Q-Q图 stat_quantile 连续的分位线 stat_smooth 添加平滑曲线 stat_spoke 绘制有方向的数据点(由x和y指定位置,angle指定角度) ...
> mystats <- function(x,na.omit=FALSE) + { + if(na.omit) + x <- x[!is.na(x)] + m <- mean(x) + n <- length(x) + s <- sd(x) + #计算偏度 + skew <- sum((x-m)^3/s^3)/n + #计算峰度 + kurt <- sum((x-m)^4/s^4)/n-3 ...