[R] ggplot2 boxplot confusion
Chris Friedl
cfriedalek at gmail.com
Thu Feb 28 05:44:51 CET 2008
hadley wrote:
>
>> I noticed the coord flip problem during my ggplot investigations. Is
>> this
>> something I can override by getting into the code?
>
> However, there is one geom that is parameterised in the opposite
> direction: geom_vline. So your second option "just draw the density
> plots with vertical lines drawn at the median, IQR etc), is fairly
> easy in the development version of ggplot:
>
> q5 <- function(x) unname(quantile(x, c(0.05, 0.25, 0.5, 0.75, 0.95)))
> qplot(carat, data=diamonds, geom="density") + geom_vline(intercept="q5")
>
> (this won't work in the current version because I've only just allow
> geom_vline to use a function to calculate the intercept). I can send
> you a copy of the development version if you let me know your OS.
>
>
>
I discovered geom_vline today. This idea works for me as a boxplot
alternative. As per example in the ggplot2 online docs I can plot multiple
density plots with median lines or fivenums colored by factor.
eg.
series <- c('C2','C4','C8','C10','C15','C20')
ids <- c('ID1','ID2','ID3')
mydata <- data.frame(SERIES=rep(series,30),ID=rep(ids,60),VALUE=rnorm(180))
df <- data.frame(series=levels(mydata$SERIES),
intercept=tapply(mydata$VALUE, list(mydata$SERIES), median))
p <- ggplot(mydata, aes(x=VALUE)) + geom_density(aes(color=SERIES))
p + geom_vline(data=df, aes(color=factor(series)))
However I can't seem to get this to work if I add a facet_grid() layer to
get a grid of density plots against two factors.
p + geom_vline(data=df, aes(color=factor(series))) + facet_grid(SERIES ~ ID)
Each grid is a single density plot in this case but each density plot has
all median vlines. I suspect I've set up the vline data frame incorrectly
but I can't see where with my noob glasses on.
And, yes I'd be happy to try dev code. I'm running on Windows XP. Should I
report problems with the dev code in this forum? Please advise.
As for writing my own stat_boxplot etc, I wouldn't mind looking at the code
to see what rolling my own would take. It might help me grasp all the
countless functions in R. But where is the source? I seem to recall a thread
of yours about the merits or otherwise of putting ggplot code on R-forge
etc.
--
View this message in context: http://www.nabble.com/ggplot2-boxplot-confusion-tp15706116p15729573.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list