[R] how to add 95% confidential interval as vertical lines to x axein density plot

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Aug 24 10:35:58 CEST 2009


Show us how you extract the confidence interval from the functions in
the hdrcde library and then we might be able to help you.

HTH,

Thierry
 


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Mao Jianfeng
Verzonden: maandag 24 augustus 2009 9:40
Aan: r-help at r-project.org
Onderwerp: [R] how to add 95% confidential interval as vertical lines to
x axein density plot

Dear R-help listers,

I want to add 95% confidential interval as vertical lines to x axe in
density plot. I have found the library(hdrcde) can do this work, but I
do not know how to handle functions of this library when I used ggplot2
to draw the graph.

Thank you in advance.

The data and codes followed:

# dummy data
factor<-rep(c("Alice","Jone","Mike"),each=100)
factor<-factor(factor)
traits1<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits2<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits3<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits4<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits5<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits6<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits7<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits8<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits9<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits10<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits11<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits12<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits13<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits14<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits15<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits16<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits17<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits18<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits19<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6)) traits20<-c(rnorm(100, mean=1, sd=1),
rnorm(100, mean=3, sd=3), rnorm(100, mean=6, sd=6))
traits21<-c(rnorm(100, mean=1, sd=1), rnorm(100, mean=3, sd=3),
rnorm(100, mean=6, sd=6))

myda<-data.frame(factor,traits1,traits2,traits3,traits4,traits5,traits6,
traits7,traits8,traits9,traits10,traits11,traits12,traits13,traits14,tra
its15,traits16,traits17,traits18,
traits19,traits20,traits21)


library(ggplot2)
d = melt(myda, id = "factor")

str(d)

pdf("test33.pdf")
p =
ggplot(data=d, mapping=aes(x=value, y=..density..)) +
facet_wrap(~variable)+ stat_density(aes(fill=factor), alpha=0.5, col=NA,
position = 'identity') + stat_density(aes(colour = factor), geom="path",
position = 'identity')
print(p)
dev.off()

Mao J-F

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.




More information about the R-help mailing list