0

I am using autoplot() in R to create a biplot for wine dataset. Currently I have the correct plot, purple is white wines and red is red wines but no matter what I try I cannot get a legend to appear. I need a legend to the right of the plot.

autoplot(wine.pca, colour = colvec1[as.factor(wine$Colour)], label.size = 3, 
         loadings=TRUE, loadings.label=TRUE, loadings.label.colour='black',
         loadings.label.vjust = 0,loadings.label.hjust=0,
         loadings.colour='black', scale=0, loadings.label.size=6, repel=TRUE)+
  xlab("Prinicpal component 1 (25.4%)")+
  ylab("Principal component 2 (22.1%)")+
  ggtitle("PC1 vs PC2")+
  theme(plot.title=element_text(hjust=0.5, size=25))+
  guides(fill=TRUE)+
  theme(axis.title = element_text(size=15))+
  scale_colour_manual("Type", values= colvec1, labels=wine$Colour, drop=FALSE)+
  theme(legend.position="right")

output of the code generates this plot but there is no legend

I have tried all sorts, scale_color_manual, scale_color_fill, element_text for lengend and all sorts however no matter what nothing ever appears

bee761
  • 25
  • 3
  • You won't get a legend by adding a scale. If you want to get a legend you have to map on aesthetics. Unfortunately your example is not reproducible, i.e. we don't have the data to run your code. For more help I would suggest to provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including working and runnable and a snippet of your data or some fake data to reproduce your issue. – stefan Oct 26 '22 at 10:10
  • Please share sample data using `dput`. – Shubham Oct 31 '22 at 18:31

0 Answers0