I am using the autoplot() function to add ellipsis and polygons to my PCA plot in R, my colour palette for the points is the color.brewer 'Set2' palette. When I am filling my ellipsis with geom='polygon', I want the polygon fill colour to be the same as the colour of the points they are covering, so as to match the palette I am using.

However I get a "'mapping' must be creates using aes()" or "Aesthetics are not valid data columns" error.

I'm a novice in R so any help would be very much appreciated.

autoplot(pca_data + aes(color = group)+      # colours
           ggtitle('Principal Component Analysis')+         # title
           theme(plot.title = element_text(hjust = 0.5))+  #centred title
           stat_ellipse(lwd = 0.75,
                        linetype = 2,
                        geom='polygon',
                        aes(fill = group),
                        alpha = 0.25,
                        show.legend = F,
                        level = 0.8) +
           scale_color_brewer(palette = "Set2")) # ellipsis 

This is my current working and will only fill the polygons to match the default colours of the PCA plot, and not to the color palette I want to use

0

There are 0 answers