Hi!
I am encountering an awkward problem when producing violin plots and using the position_jitterdodge.
(Reproducible code to illustrate my example follows in the end of the post)
If you compare the resulting figures and the annotated areas you will see that there there are several points that will not be drawn on the violin plot (probably more than I have discovered). To me this seems problematic, although a minor issue.
Do you see any fixes to this issue or is it a feature to reduce overplotting? I imagine it might be a bigger problem in some charts than in the example provided here.
Thanks for any comment on this =)
-Alex
library(tidyverse)
# Setting up example
id <- rep(1:30, 3)
type <- rep(
c(rep("sca", 8), rep("fca", 22)), 3)
data <- c(
rep("Gene 1", 30),
rep("Gene 2", 30),
rep("Gene 3", 30))
set.seed(123)
value1 <- c(rnorm(8, 0.48, sd=0.41), rnorm(22, 2.5, sd=2.))
value2 <- c(rnorm(8, 0.14, sd=0.14), rnorm(22, 2.6, sd=1.8))
value3 <- c(rnorm(8, 0.3, sd=0.2), rnorm(22, 1.39, sd=1.2))
tidydata2 <- tibble(id=id, type=type, data=data, value=c(value1, value2, value3))
pl <- ggplot(tidydata2, aes(x=data, y=value, color=type), alpha=1)
###################
# boxplot m/points + y_log10
###################
pl+ geom_boxplot()+
geom_point(position = position_jitterdodge(jitter.width = 0.18, jitter.height = 0, seed = 1234))+
ylab("Relative gene expression")+
xlab("")+
scale_y_log10()+
theme_minimal()+
annotate("rect", xmin=0.7, xmax=1, ymin=0.18, ymax=0.28, alpha=0.2)+
annotate("rect", xmin=2, xmax=2.3, ymin=0.085, ymax=0.12, alpha=0.2)
ggsave("boxplot.png")
###################
# Violin m/points + y_log10
###################
pl+ geom_violin(scale="width")+
geom_point(position = position_jitterdodge(jitter.width = 0.18, jitter.height = 0, seed = 1234), alpha=0.9)+
ylab("Relative gene expression")+
xlab("")+
scale_y_log10()+
theme_minimal()+
annotate("rect", xmin=0.7, xmax=1, ymin=0.18, ymax=0.28, alpha=0.2)+
annotate("rect", xmin=2, xmax=2.3, ymin=0.085, ymax=0.12, alpha=0.2)
ggsave("violinplot.png")