Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R geom_密度:不同x轴值的着色密度曲面_R_Ggplot2_Plot_Tidyverse_Figure - Fatal编程技术网

R geom_密度:不同x轴值的着色密度曲面

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

我应该如何更改代码以获得所需结果:相当于“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.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)
#模拟零膨胀数据
圆周率