NinaShch
NinaShch

Reputation: 1

Using multiple continuous colour palettes in one graph (ggplot2 and/or ggfortify)

Yet another R novice working on visualisation of some basic PCA. I'm not even sure how to present this question in a clear way:)

Basically, I have the following code, where in the original df col1 has n>3 individual rows that belong to 3 different groups in col2:

df.pca.plot <- autoplot(df.pca, data = df, colour = 'col1', shape='col2')

What I get is a graph, where some colours of different shapes are closer than the colours within a shape group (e.g. triangles range in colour from pink to blue, but some triangles and some diamonds are of different shades of blue). I was wondering if I can specify not just different single colours for col2 groups, but different palettes (e.g. all triangles are of various shades of purple, all diamonds - shades of orange, all circles - shades of green). So within each subgroup they are still continuous?

Putting "colour='col1'&'col2'" naturally failed.

So far I'm tempted to either simplify it to having both colour and shape defined just by col2 (3 groups) or try and use labels from col1 instead of shapes on the graph itself rather than in legend. But finding a way around it would be much more interesting and helpful for future work:)

UPD: Meanwhile I came up with another question - I'm using a specified colour palette for the groups from col1 (drawing ellipses with fviz_pca_ind) but wanted to use predetermined three colours for labels (groups from col2). So far I can only use the three colours from the same colour palette, instead of customising them...

fviz_pca_ind(df.pca,
             col.ind = col1, # color by groups
             geom="point",
             palette = paletteer_c("grDevices::rainbow", 26), #I have only 23 vars in col1, but bc of adding three groups from col2 below, R asks me to put 26 for this palette
             addEllipses = TRUE, # Concentration ellipses
             ellipse.type = "confidence",
             repel = TRUE)+
  geom_text_repel(aes(label=rownames(df), colour=df$col2), show.legend=FALSE)  #I tried putting scale_colour_manual within and outside the last aes but so far no result...

Upvotes: 0

Views: 102

Answers (0)

Related Questions