2014-03-02 1 views
1

일부 합성 실험을 실행 중입니다.ggplot을 사용하여 밀도 플롯의 x 축에 빨간색 점을 추가하는 방법

나는 3 개의 매개 변수 분포 (m)와 각 매개 변수의 실제 값 (trueValues)을 가지고 있습니다.

library('reshape2') 
library('ggplot2') 

trueValues <- c("V1"=0,"V2"=2.5,"V3"=5) 
set.seed(1) 
m <- matrix(cbind("V1"=rnorm(5, 0), "V2"=rnorm(5, 2), "V3"=rnorm(5, 5)), nrow=5, ncol=3) 
df <- melt(m) 
ggplot(df, aes(x=value)) + geom_density() + facet_wrap(~Var2) 

어떻게하면 x 축에 빨간색 점을 그려 실제 값을 표시 할 수 있습니까?

enter image description here

답변

3

당신은 시도 할 수 있습니다 :

trueValues <- data.frame("Var2" = c(1, 2, 3), "value" = c(0, 2.5, 5)) 
ggplot(df, aes(x=value)) + geom_density() + facet_wrap(~Var2) + geom_point(data = trueValues, y = 0, color="red") 

enter image description here

+0

우수함! 많은 감사. – Claudia

관련 문제