boxplot + jitter -- display problem for multiple parameters

130 views
Skip to first unread message

Meesters, Christian

unread,
Nov 21, 2011, 8:10:33 AM11/21/11
to ggp...@googlegroups.com
Hi,

I am dealing with a dataset like:

ID Status par1 par2 par3
1 Z 0.1 0.05 0.06
2 Z 0.3 0.34 1.2
3 C 0.4 0.5 0.8
...

Here, the 'Status' column indicates case/control status ('Z' for cases and 'C' for controls). The dataset is attached as 'dataset'.

Is there a way to gain two box plots (with "jitterred" points) for each parameter (par1 to par3) and each status?

I've tried
p <- ggplot()
p <- p + layer(data = dataset, geom = c("jitter", "boxplot"), mapping = aes(x = Status, y = par1)
and already I run into the problem that I only see jittered points, but no boxplot. Also, I did not figure out how to create a facet plot for arbitrary parameters (par1 to parx).

Any pointers for me?

TIA
Christian

Brandon Hurr

unread,
Nov 21, 2011, 12:24:26 PM11/21/11
to Meesters, Christian, ggp...@googlegroups.com
Christian, 

I do not see an attached dataset. Could you try sending it again?

B

Christian

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Brandon Hurr

unread,
Nov 22, 2011, 3:32:33 AM11/22/11
to Meesters, Christian, ggp...@googlegroups.com
"The dataset is attached as 'dataset'." Can be interpreted in more
than one way.

Anyway...
This gets you the jittered points and boxplot.
#############
require(ggplot2)
dataset <- read.csv('/Users/brandonhurr/Desktop/data.csv')
ggplot(data = dataset, aes(x = Status, y = par1)) + geom_boxplot()+geom_jitter()
ggsave("test.png", dpi = 200)
###############You'll need to melt your dataset using reshape
##############
require(reshape2)

m.dataset<-melt(dataset, id.vars=c("ID", "Status"), value.name="par")

ggplot(data = m.dataset, aes(x = Status, y = value)) +
geom_boxplot()+
geom_jitter()+
facet_grid(.~variable)+
labs(x="X axis Title", y="Yaxistitle, Status")
##############


HTH,

Brandon

2011/11/22 Meesters, Christian <mees...@aesku.com>
>
> I did not speak of any attached dataset. Anyway, here it is, including a minimal example. No meaningful data and also too few, but the main point gets visible: There are only jittered points, no boxplots. The same is true for larger datasets.
> Also, I do not know how to display this pair of case / control boxplots for all parameters (I might not know the parameter names in advance).
>
> Thanks,
> Christian
>
>
> ________________________________
> From: Brandon Hurr [brando...@gmail.com]
> Sent: Monday, November 21, 2011 6:24 PM
> To: Meesters, Christian
> Cc: ggp...@googlegroups.com
> Subject: Re: boxplot + jitter -- display problem for multiple parameters

test.png
melted.test.png

Brandon Hurr

unread,
Nov 22, 2011, 3:55:23 AM11/22/11
to Meesters, Christian, ggp...@googlegroups.com
Sadly, I think reshape(1) is overriding reshape2 in the current build
(it is ignoring "value.name" in this case). Hadley is trying to
deprecate reshape1 because of it's inefficiencies, but it is still
required for ggplot2 0.89. Once 0.90 is out you should use reshape2
for your melting/casting needs.

Brandon

On Tue, Nov 22, 2011 at 08:49, Meesters, Christian <mees...@aesku.com> wrote:
> Oh, indeed, "attach" in R-related mailing lists should be used with little more caution. Stupid me.
>
> Anyway, your snippet does the trick. I was unaware of reshape2 - thanks a lot.
>
> Cheers,
> Christian
>
> ________________________________________
> From: Brandon Hurr [brando...@gmail.com]
> Sent: Tuesday, November 22, 2011 9:32 AM

Meesters, Christian

unread,
Nov 22, 2011, 3:49:46 AM11/22/11
to Brandon Hurr, ggp...@googlegroups.com
Oh, indeed, "attach" in R-related mailing lists should be used with little more caution. Stupid me.

Anyway, your snippet does the trick. I was unaware of reshape2 - thanks a lot.

Cheers,
Christian

________________________________________
From: Brandon Hurr [brando...@gmail.com]


Sent: Tuesday, November 22, 2011 9:32 AM

Meesters, Christian

unread,
Nov 22, 2011, 2:49:42 AM11/22/11
to Brandon Hurr, ggp...@googlegroups.com
I did not speak of any attached dataset. Anyway, here it is, including a minimal example. No meaningful data and also too few, but the main point gets visible: There are only jittered points, no boxplots. The same is true for larger datasets.
Also, I do not know how to display this pair of case / control boxplots for all parameters (I might not know the parameter names in advance).

Thanks,
Christian



From: Brandon Hurr [brando...@gmail.com]
Sent: Monday, November 21, 2011 6:24 PM
To: Meesters, Christian
Cc: ggp...@googlegroups.com
Subject: Re: boxplot + jitter -- display problem for multiple parameters

data.csv
eval.r
Reply all
Reply to author
Forward
0 new messages