I ran a PCA and customized it via ggplot (on DESeq2 RNAseq data). Everything looks well excepted the legend that appears all black for the 2 genotypes (see the Genotype legend on right of the picture) while the PCA itself looks great (genotype 1 is well colored in green and genotype 2 colored in red, both individualy shaped with a dark border line). I have tried many writings but I am stucked concerning the legend looking. Thanks for help.
The script :
############# PCA
names<-colnames(rld)
pcaData <- plotPCA(rld, intgroup=c("Genotype", "Treatment"), returnData=TRUE)
percentVar <- round(100 * attr(pcaData, "percentVar"))
ggplot(pcaData, aes(PC1, PC2, color=Genotype, shape=Treatment, fill=Genotype, label=names)) +
geom_point(size=3) +
ggtitle("PCA | Prunus") +
theme(legend.position = "right") +
xlab(paste0("PC1: ",percentVar[1],"% variance")) +
ylab(paste0("PC2: ",percentVar[2],"% variance")) +
coord_cartesian()+
scale_shape_manual(values=c(21,23))+
scale_color_manual(values = c("#000000", "#000000")) +
scale_fill_manual(values = c("#78D212", "#C12D0D")) +
stat_ellipse(type = "norm", geom="polygon", level=0.8,alpha=0.2)+
theme(
axis.line = element_line(colour = "black", size = 1, linetype = "solid"),
panel.background = element_rect(fill = "white", colour = "black", size = 2, linetype = "solid"),
panel.grid.major = element_line(colour ="grey", size = , linetype = "dashed"),
panel.grid.minor = element_line(colour ="black", size = , linetype = "dashed")
)
The graph (see the 2 black circles in the genotype legend (instead of expected green and red + black line)):
Below are some tests I have done according to comments.
Thanks for your help.