I want to plot a common legend outside of the plotting area in a device having multiple plots. Using the code below, the common legend is displayed correctly in the plot preview in RStudio, but when I save the plot as PDF the common legend is not displayed in the PDF.
How do I need to modify my code in order to have the legend displayed in the PDF?
This is my code:
maxmin <- data.frame(
v1=c(1,0),
v2=c(1,0),
v3=c(1,0),
v4=c(1,0),
v5=c(1,0),
v6=c(1,0))
dd<-data.frame(
v1 = c(0, 0.13, 0.25, 0.38, 0.5, 0.23, 0.9, 0.85, 1, 1, 0, 0.3, 0.3, 0.7),
v2 = c(0.1, 0.8, 0.63, 1, 0.2, 0.5, 0.4, 0.8, 0.9, 0.1, 0.1, 0.2, 1, 0.45),
v3 = c(0.12, 0.84, 1, 0.54, 0.9, 0.88, 0.9, 0.3, 0.1, 0.9, 0.45, 0.66, 0.3, 0.7),
v4 = c(0.23, 0.7, 1, 0.67, 0.9, 0.88, 0.3, 0.3, 0.1, 0, 0.45, 0.66, 0.3, 0.7),
v5 = c(0.33, 0.6, 0.1, 0.9, 0.9, 0.4, 0.9, 0.9, 0.1, 0.9, 0.45, 0.3, 0.3, 0.7),
v6 = c(1, 0.77, 1, 0.59, 0.1, 0.88, 0.9, 0.3, 0.1, 0.3, 0.45, 0.66, 0.2, 0.7)
)
dat <- rbind(maxmin,dd)
dat.sub1 <- dat[1:4,]
dat.sub2 <- dat[c(1,2,5,6),]
dat.sub3 <- dat[c(1,2,7,8),]
dat.sub4 <- dat[c(1,2,9,10),]
dat.sub5 <- dat[c(1,2,11,12),]
dat.sub6 <- dat[c(1,2,13,14),]
par(mfrow=c(3,2))
radarchart(dat.sub1, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification A1", vlcex=0.5)
radarchart(dat.sub2, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification A1", vlcex=0.5)
radarchart(dat.sub3, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification B1", vlcex=0.5)
radarchart(dat.sub4, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification B2", vlcex=0.5)
radarchart(dat.sub5, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification C1", vlcex=0.5)
radarchart(dat.sub6, vlabels=c("One", "Two", "Three", "Four", "Five", "Six"), title="Classification C2", vlcex=0.5)
op <- par(usr=c(0,1,0,1),
xpd=NA)
legend(-0.5,0,
c("Male", "Female"), lty=1, lwd=3, col=c("red", "black"), box.col=NA)
This is a screenshot of the plot preview in RStudio (the legend appears):
This is how the PDF looks like (the legend does not appear):
In writing the code, I basically followed this post: