Discussion:
Violinplot and discrete values
Raf Winand
2012-12-06 14:11:58 UTC
Permalink
I'm trying to create a violin plot in R from count data. The data I use is
a number of mutations that is found in each sample for each source.

It looks something like this but then for more than a thousand rows:

mutationsnames161kG261kG361kG461kG561kG661kG761kG861kG951kG1051kG1151kG

I already use the code below to create several plots.

ggplot(df_combined, aes(factor(names), y=mutations)) +
geom_violin() +
geom_boxplot(width=.1, outlier.size=0, fill="grey50") +
stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=4) +
xlab("Source") +
ylab("Number of mutations") +
theme(axis.text = element_text(colour = "black"))`

While most of them show up just fine, some of them start to 'wobble' (best
way I can explain it) Here is a link to an example that doesn't work.

<Loading Image...>

I guess this is because my data is discrete and not continuous but I can't
find anything on how to change this for the violin plot. Is there any way I
can get this to work with ggplot2 and geom_violin?
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Winston Chang
2012-12-06 16:39:53 UTC
Permalink
You can use the "adjust" parameter, like geom_violin(adjust=2).

Since geom_violin uses (by default) stat_ydensity, you can look in
?stat_ydensity - this in turn will point you to ?density, since that's the
function that does the actual calculation.

-Winston
Post by Raf Winand
I'm trying to create a violin plot in R from count data. The data I use is
a number of mutations that is found in each sample for each source.
mutations names 1 6 1kG 2 6 1kG 3 6 1kG 4 6 1kG 5 6 1kG 6 6 1kG 7 6 1kG861kG951kG1051kG1151kG
I already use the code below to create several plots.
ggplot(df_combined, aes(factor(names), y=mutations)) +
geom_violin() +
geom_boxplot(width=.1, outlier.size=0, fill="grey50") +
stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=4) +
xlab("Source") +
ylab("Number of mutations") +
theme(axis.text = element_text(colour = "black"))`
While most of them show up just fine, some of them start to 'wobble' (best
way I can explain it) Here is a link to an example that doesn't work.
<http://imgur.com/0M579.jpg>
I guess this is because my data is discrete and not continuous but I can't
find anything on how to change this for the violin plot. Is there any way I
can get this to work with ggplot2 and geom_violin?
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Ben Bolker
2012-12-06 17:21:25 UTC
Permalink
Received: by 10.50.213.33 with SMTP id np1mr759325igc.3.1354814496901;
Thu, 06 Dec 2012 09:21:36 -0800 (PST)
X-BeenThere: ggplot2-/***@public.gmane.org
Received: by 10.50.163.38 with SMTP id yf6ls2494034igb.12.gmail; Thu, 06 Dec
2012 09:21:32 -0800 (PST)
Received: by 10.43.81.196 with SMTP id zz4mr1741823icb.14.1354814492363;
Thu, 06 Dec 2012 09:21:32 -0800 (PST)
Received: by 10.43.81.196 with SMTP id zz4mr1741822icb.14.1354814492321;
Thu, 06 Dec 2012 09:21:32 -0800 (PST)
Received: from mail-ie0-f179.google.com (mail-ie0-f179.google.com [209.85.223.179])
by gmr-mx.google.com with ESMTPS id x4si1746680igm.0.2012.12.06.09.21.32
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 06 Dec 2012 09:21:32 -0800 (PST)
Received-SPF: pass (google.com: domain of bbolker-***@public.gmane.org designates 209.85.223.179 as permitted sender) client-ip=209.85.223.179;
Received: by mail-ie0-f179.google.com with SMTP id k14so10243645iea.38
for <ggplot2-/***@public.gmane.org>; Thu, 06 Dec 2012 09:21:32 -0800 (PST)
Received: by 10.50.219.129 with SMTP id po1mr6447927igc.35.1354814492215;
Thu, 06 Dec 2012 09:21:32 -0800 (PST)
Received: from [192.168.104.174] (d24-36-79-105.home1.cgocable.net. [24.36.79.105])
by mx.google.com with ESMTPS id fa6sm7605804igb.2.2012.12.06.09.21.30
(version=SSLv3 cipher=OTHER);
Thu, 06 Dec 2012 09:21:31 -0800 (PST)
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To: <CAFOpNVGXUffgrCEqgsVKB7qSxf+Kk5Tsnb3hp88DfErnRi0LiA-JsoAwUIsXosN+***@public.gmane.org>
X-Enigmail-Version: 1.4.6
X-Original-Sender: bbolker-***@public.gmane.org
X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
domain of bbolker-***@public.gmane.org designates 209.85.223.179 as permitted sender)
smtp.mail=bbolker-***@public.gmane.org; dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list ggplot2-/***@public.gmane.org; contact ggplot2+owners-/***@public.gmane.org
List-ID: <ggplot2.googlegroups.com>
X-Google-Group-Id: 604545605438
List-Post: <http://groups.google.com/group/ggplot2/post?hl=en>, <mailto:ggplot2-/***@public.gmane.org>
List-Help: <http://groups.google.com/support/?hl=en>, <mailto:ggplot2+help-/***@public.gmane.org>
List-Archive: <http://groups.google.com/group/ggplot2?hl=en>
Sender: ggplot2-/***@public.gmane.org
List-Subscribe: <http://groups.google.com/group/ggplot2/subscribe?hl=en>, <mailto:ggplot2+subscribe-/***@public.gmane.org>
List-Unsubscribe: <http://groups.google.com/group/ggplot2/subscribe?hl=en>, <mailto:googlegroups-manage+604545605438+unsubscribe-/***@public.gmane.org>
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.r.ggplot2/6499>

Note that this is cross-posted to StackOverflow:

http://stackoverflow.com/questions/13744979/violinplot-in-r-with-discrete-values

Cross-posting is not forbidden (although some people dislike it
because it may waste people's effort coming up with the same parallel
solutions in different places), but it is definitely polite to note that
you are cross-posting, and provide links as appropriate ...
Post by Winston Chang
You can use the "adjust" parameter, like geom_violin(adjust=2).
Since geom_violin uses (by default) stat_ydensity, you can look in
?stat_ydensity - this in turn will point you to ?density, since that's
the function that does the actual calculation.
-Winston
I'm trying to create a violin plot in R from count data. The data I
use is a number of mutations that is found in each sample for each
source.
mutations names
1 6 1kG
2 6 1kG
3 6 1kG
4 6 1kG
5 6 1kG
6 6 1kG
7 6 1kG
8 6 1kG
9 5 1kG
10 5 1kG
11 5 1kG
I already use the code below to create several plots.
|ggplot(df_combined, aes(factor(names), y=mutations)) +
geom_violin() +
geom_boxplot(width=.1, outlier.size=0, fill="grey50") +
stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=4) +
xlab("Source") +
ylab("Number of mutations") +
theme(axis.text = element_text(colour = "black"))`|
While most of them show up just fine, some of them start to 'wobble'
(best way I can explain it) Here is a link to an example that
doesn't work.
<http://imgur.com/0M579.jpg>
I guess this is because my data is discrete and not continuous but I
can't find anything on how to change this for the violin plot. Is
there any way I can get this to work with ggplot2 and geom_violin?
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
Raf Winand
2012-12-06 18:18:21 UTC
Permalink
Thanks, that was exactly what I was looking for!
Post by Winston Chang
You can use the "adjust" parameter, like geom_violin(adjust=2).
Since geom_violin uses (by default) stat_ydensity, you can look in
?stat_ydensity - this in turn will point you to ?density, since that's the
function that does the actual calculation.
-Winston
Post by Raf Winand
I'm trying to create a violin plot in R from count data. The data I use
is a number of mutations that is found in each sample for each source.
mutations names 1 6 1kG 2 6 1kG 3 6 1kG 4 6 1kG 5 6 1kG 6 6 1kG 7 61kG861kG951kG1051kG1151kG
I already use the code below to create several plots.
ggplot(df_combined, aes(factor(names), y=mutations)) +
geom_violin() +
geom_boxplot(width=.1, outlier.size=0, fill="grey50") +
stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=4) +
xlab("Source") +
ylab("Number of mutations") +
theme(axis.text = element_text(colour = "black"))`
While most of them show up just fine, some of them start to 'wobble'
(best way I can explain it) Here is a link to an example that doesn't work.
<http://imgur.com/0M579.jpg>
I guess this is because my data is discrete and not continuous but I
can't find anything on how to change this for the violin plot. Is there any
way I can get this to work with ggplot2 and geom_violin?
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Loading...