我正在尝试用计数数据在R中创建一个小提琴曲线。我使用的数据是每个样本中为每个来源发现的一些突变。
它看起来像这样:
2 Source1
8 Source2
0 Source1
1 Source1
9 Source2
...
我已经使用下面的代码创建了几个图。
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"))`
虽然它们中的大部分显示得很好,但其中一些开始“摆动”(最好的解释方法)以下是一个不起作用的例子。
我想这是因为我的数据是离散的而不是连续的但我找不到任何关于如何改变小提琴情节的信息。有什么方法可以让它与ggplot2和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")