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")