2

I am running a PCA with the DESeq2 package and would like to obtain a black outline on the shapes which are already based on an observation.The round ones work, but the other shapes do not.

Examples such as Make stat_ellipse {ggplot2} outline geom_point fill color or Place a border around points have data plotted as one only shape.

It is hard to give a reproducible example as it has previously performed a PCA on a big dataset, but this is what I have run the following:

ggplot(pcaData, aes(x = PC1, y = PC2, color = dFe, shape = location))+   
geom_point(size=5)+  
geom_point(aes(PC1, PC2, color = dFe, shape = location), shape= 21, colour="black", size= 5)

I believe the key is on the coding of that new layer of geom_point

enter image description here

Running scale_fill_manual I get the following

ggplot(pcaData, aes(x = PC1, y = PC2, color = dFe, shape = location))+   
geom_point(size=5)+  scale_shape_manual(values=c(21,22,23))

enter image description here

Ecg
  • 908
  • 1
  • 10
  • 28
  • 1
    Just a quick thought, did you try plotting geom points with black color of some bigger size and again plotting geom points with color of smaller size? – Mohanasundaram Nov 24 '20 at 15:54
  • I edited the image, so the size of the black outline is the same and coincides with the round shapes, but not with the triangles and squares, does this make sense? – Ecg Nov 24 '20 at 15:58
  • 1
    `shape = 21` is overriding the shape aesthetic. Remove it. Use a `scale_shape_manual` to provide hollow (or bordered) shapes matching the locations. – Konrad Rudolph Nov 24 '20 at 15:59
  • @KonradRudolph I edited the post, the outline changes but the fill is now gone... – Ecg Nov 24 '20 at 16:12
  • 1
    @Ecg So provide one. — See my answer. – Konrad Rudolph Nov 24 '20 at 16:16

2 Answers2

2

As mentioned in my comment, use scale_shape_manual, and provide a fill aesthetic:

ggplot(pcaData, aes(x = PC1, y = PC2, fill = dFe, shape = location)) +
    geom_point(color = 'black', size = 5) +
    scale_shape_manual(values = c(21L, 22L, 23L))

enter image description here

Ecg
  • 908
  • 1
  • 10
  • 28
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
1

Try This:

ggplot(pcaData, aes(x = PC1, y = PC2, shape = location))+   
  geom_point(size=7) + 
  geom_point(aes(x = PC1, y = PC2, color = dFe, shape = location), size=5)

enter image description here

Mohanasundaram
  • 2,889
  • 1
  • 8
  • 18