I don't know if you can get the information from the plot, but you can certainly get it from the density() function directly. For example,
# fake data TestVar <- rnorm(60) type <- rep(c("Bottom", "Other", "Top"), 20) # density of TestVar for each type, estimated at 100 points along range of TestVar d <- tapply(TestVar, type, density, from=min(TestVar), to=max(TestVar), n=100) results <- data.frame(TestVar=d$Top$x, sapply(d, "[[", 2)) # select only those records where the Top density is greater than the Bottom density results[results$Top > results$Bottom, ] Jean On Thu, Jun 12, 2014 at 10:25 PM, Parimal Lokhande < parimallokha...@gmail.com> wrote: > I have a dataframe > âdf â > with 3 columns. Details > âof df are â > as follows > > > summary(df) > Date TestVar type > Min. :2002-05-10 00:00:00 Min. :-3.8531 Bottom: 313 > 1st Qu.:2005-05-09 12:00:00 1st Qu.:-0.7773 Other :2501 > Median :2008-05-07 00:00:00 Median : 0.2482 Top : 313 > Mean :2008-05-07 00:00:00 Mean : 0.1980 > 3rd Qu.:2011-05-05 12:00:00 3rd Qu.: 1.2250 > Max. :2014-05-05 00:00:00 Max. : 3.6633 > > > > str(df) > 'data.frame': 3127 obs. of 3 variables: > $ Date : POSIXlt, format: "2002-05-10" "2002-05-13" "2002-05-14" ... > $ TestVar: num 1.34 2.02 1.39 1.54 2.45 ... > $ type : Factor w/ 3 levels "Bottom","Other",..: 3 3 3 3 3 3 3 3 2 2 ... > > I have plotted the following density plot for column 2 i.e. TestVar and > then > color coded according to factor variable "type" > > <http://r.789695.n4.nabble.com/file/n4691999/Rplot01.jpeg> > > > ggplot(df)+ geom_density(aes(x=TestVar, color=type)) > > > > I now want to filter out data samples such that the density > âcurve > of "Top" is > higher than "Bottom". Basically I need TestVar values for which blue line > is > higher than red line. > > How can this be achieved? Is there a way i can extract density values out > of > the plot? > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > > [[alternative HTML version deleted]]
______________________________________________ R-help@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.