I am attempting to use the following code to split my long line of text into multiple lines in the legend of a pie chart. The current code creates a legend with a lot of white space and the text runs over the box. The box is also over the pie chart. What am I doing wrong?
v4_class_combined_slices <- c(27, 121, 27)
v4_class_combined_labels <- c("Bacteroidia", "Clostridia", "Actinobacteria/Coriobacteriia/\n4C0d.2/Bacilli/Erysipelotrichi/\nBetaproteobacteria/Gammaproteobacteria/\nMollicutes/RF3")
piepercent <- round(100*v4_class_combined_slices/sum(v4_class_combined_slices), 1)
piepercent2 <- paste(piepercent, sep = " ", "%")
pie(v4_class_combined_slices, labels = piepercent2, col = rainbow(3))
legend("topright", v4_class_combined_labels, cex = 0.9, text.width = 1.5, yjust = 0, fill = rainbow(length(v4_class_combined_labels)))