我想在具有多个绘图的设备中绘制绘图区域外的常见图例。使用下面的代码,在RStudio的绘图预览中正确显示了常见图例,但是当我将绘图保存为PDF时,常见图例不会显示在PDF中。
如何修改代码以便在PDF中显示图例?
这是我的代码:
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)
这是RStudio中的情节预览的截图(图例中显示):
这就是PDF的样子(图例没有出现):
在编写代码时,我基本上都遵循了这篇文章: