R中的小提琴图,具有离散值 [英] Violinplot in R with discrete values

查看:83
本文介绍了R中的小提琴图,具有离散值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据计数数据在R中创建小提琴图.我使用的数据是在每种来源的每个样本中发现的许多突变.

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.

它看起来像这样:

2 Source1
8 Source2
0 Source1
1 Source1
9 Source2
...

我已经使用下面的代码创建了多个图.

I already used 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 an example that doesn't work.

我想这是因为我的数据是离散的而不是连续的,但是我找不到有关如何更改小提琴图的任何信息.有什么办法可以使它与ggplot2和geom_violin一起使用?

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?

以下数据:

structure(list(mutations = c(6, 6, 6, 6, 6, 6), names = structure(c(1L, 1L, 1L, 1L, 1L,   
1L), .Label = c("1kG", "CG"), class = "factor")), .Names = c("mutations", "names"), 
row.names = c(NA, 6L), class = "data.frame") 

推荐答案

我从Winston Chang

I got the answer from Winston Chang on the ggplot2 forum. The trick is to use geom_violin(adjust=2), which will make the graph smooth.

这篇关于R中的小提琴图,具有离散值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆