I have a melted dataframe df
with first column sample names
, second column Group
, third column Genes
, fourth column Expression (logCPM)
.
head(df)
sample names Group Genes Expression (logCPM)
Sample1 GroupA Gene1 3.45
Sample2 GroupA Gene1 2.34
Sample3 GroupA Gene1 0.5667
Sample4 GroupA Gene1 1.98
Sample5 GroupA Gene1 0.45
Sample6 GroupB Gene1 4.566
Sample7 GroupB Gene1 0.5667
I'm trying to make a violin plot combining box plot with following code:
positions <- c("GroupA", "GroupB")
e <- ggplot(df, aes(x = Genes, y = Expression (logCPM)))
e2 <- e + geom_violin(
aes(color = Group), trim = FALSE,
position = position_dodge(0.9), draw_quantiles=c(0.5)) +
geom_boxplot(
aes(color = Group), width = 0.01,
position = position_dodge(0.9)) +
scale_color_manual(legend_title, values = c("GroupA"="#FC4E07", "GroupB"="#00AFBB")) +
theme_bw(base_size = 14) + xlab("") + ylab("Expression (logCPM)") +
theme(axis.text=element_text(size=15, face = "bold", color = "black"),
axis.title=element_text(size=15, face = "bold", color = "black"),
strip.text = element_text(size=15, face = "bold", color = "black"),
axis.text.x = element_text(angle = 0),
legend.text=element_text(size=12, face = "bold", color = "black"),
legend.title=element_text(size=15,face = "bold", color = "black"))
e2
I am trying to create violin plots with boxplots within each violin plot. But it doesn't look good. It doesn't look like a violin plot instead looks like a line. Is there anything I have to correct for aligning?
The data I'm using is huge