R geom_密度:不同x轴值的着色密度曲面
我应该如何更改代码以获得所需结果:相当于“0”和“>25”的密度表面颜色为红色。R geom_密度:不同x轴值的着色密度曲面,r,ggplot2,plot,tidyverse,figure,R,Ggplot2,Plot,Tidyverse,Figure,我应该如何更改代码以获得所需结果:相当于“0”和“>25”的密度表面颜色为红色。 #simulate zero-inflated data pi <- 0.3 mu_log <- 2 sigma_log <- 0.8 N <- 1000 y <- (1 - rbinom(N, 1, prob = pi)) * rlnorm(N, mu_log, sigma_log) #plot ggplot()+ geom_density(aes(y), inherit.ae
#simulate zero-inflated data
pi <- 0.3
mu_log <- 2
sigma_log <- 0.8
N <- 1000
y <- (1 - rbinom(N, 1, prob = pi)) * rlnorm(N, mu_log, sigma_log)
#plot
ggplot()+
geom_density(aes(y), inherit.aes = FALSE, show.legend = FALSE, size = 1, fill="grey60", color = NA, outline.type = "upper")
#模拟零膨胀数据
pi以下是我可以想到的一些想法:
#simulate zero-inflated data
pi <- 0.3
mu_log <- 2
sigma_log <- 0.8
N <- 1000
y <- (1 - rbinom(N, 1, prob = pi)) * rlnorm(N, mu_log, sigma_log)
df = data.frame(y)
gg = ggplot(df, aes(y)) +
geom_density(fill = "grey")
dat = ggplot_build(gg)$data[[1]]
gg + geom_area(data = subset(dat, x > 25), aes(x = x, y = y), fill = "red") +
geom_vline(xintercept = 0, col = "red", size = 2)
#模拟零膨胀数据
圆周率