I have 4 plots, two UMAP plots (scatter plot), and two violin plots, there is a variable named "celltype" which is common among all of them, and the categorization is based on this variable.
first I plot each of them separately, then I used two subplots to concatenate them.
The problem is that users can see 4 legends for them, how can I show only one legend, because the variable and colors are the same. please see the attached picture.
This is the code:
#first UMAP
p_TF_umap <- plot_data_specific() %>%
ggplot(aes(x = UMAP1, y= UMAP2, color = celltype ))+
geom_point()+
scale_color_manual(values = setNames(c(r_color) ,c(unique(celltype))) )+
ggtitle("Meta")
#First Violin
p_TF_violin <- plot_data_violin() %>%
ggplot(plot_data_violin(), mapping = aes(x=celltype, y=feature_expr, fill = factor(celltype))) +
ggtitle("Violin Plot of Singlecell")+
labs(y= "Expression", x = "Cell Type")+
geom_violin()+
scale_fill_manual(values = setNames(c(r_color) ,c(unique(celltype))))
#second UMAP
p_TF_umap1 <- plot_data_specific1() %>%
ggplot(aes(x = UMAP1, y= UMAP2, color = celltype))+
geom_point()+
scale_color_manual(values = setNames(c(r_color) ,c(unique(celltype))))+
ggtitle("Metacell Section")
#Second violin
p_TF_violin1 <- plot_data_violin1() %>%
ggplot(plot_data_violin1(), mapping = aes(x=celltype, y=feature_expr, fill=factor(celltype))) +
ggtitle("Violin Plot of Metacell")+
labs(y= "Expression", x = "Cell Type")+
geom_violin()+
scale_fill_manual(values = setNames(c(r_color) ,c(unique(celltype))) )
#Subplot Part
Final_fig1 <- subplot(p_TF_violin1, p_TF_violin) %>%
layout(title = 'A B',
autosize =T, width = 1500, height = 900, margin = 0.1)
#Second Subplot
Final_fig1 <- subplot(Final_fig1, titleX = T, titleY = T,
margin = c(0.03),
subplot(p_TF_umap1, p_TF_umap,
margin = c(0.01, 0.04, 0.01, 0.01),
widths = c(0.5, 0.5),
titleX = T, titleY = T),
nrows = 2,
heights = c(0.5, 0.5))