1
ggplot2에서면 집합 밀도 그림의 가장 높은 (후부) 밀도 간격을 나타내는 가로선을 그릴 때는 어떻게합니까? 이것은 내가 시도 것입니다 : 내가 패 시팅을 존중하기를 원하는 반면geom_density에서 그리기 간격
# Functions to calculate lower and upper part of HPD.
hpd_lower = function(x) coda::HPDinterval(as.mcmc(x))[1]
hpd_upper = function(x) coda::HPDinterval(as.mcmc(x))[2]
# Data: two groups with different means
df = data.frame(value=c(rnorm(500), rnorm(500, mean=5)), group=rep(c('A', 'B'), each=500))
# Plot it
ggplot(df, aes(x=value)) +
geom_density() +
facet_wrap(~group) +
geom_segment(aes(x=hpd_lower(value), xend=hpd_upper(value), y=0, yend=0), size=3)
당신이 볼 수 있듯이, geom_segment
두 측면에 대한 모든 데이터를 계산합니다. 또한 HPDinterval
은 패싯 당 한 번만 실행되는 솔루션을 원합니다.