导读
Only legend, no plot. But plot first...
一、画图
欲擒故纵
plot(1)
二、擦擦擦
擦掉中间的点
plot(NULL, xlim=0:1, ylim=0:1)
擦掉xy轴的标签
plot(NULL, xlim=0:1, ylim=0:1, xlab="", ylab="")
擦掉坐标轴
plot(NULL, xlim=0:1, ylim=0:1, xlab="", ylab="", xaxt="n", yaxt="n")
擦掉框框,擦干净了
plot(NULL, xlim=0:1, ylim=0:1, xlab="", ylab="", xaxt="n", yaxt="n", bty="n")
三、画图例
写点什么
legend("topleft", legend=c("子", "丑", "寅", "卯"))
legend("center", legend=c("甲", "乙", "丙", "丁"))
legend("bottomright", legend=c("上", "下", "左", "右"))
加图、上色。挑喜欢的图,上喜欢的色。pch参数可控制图例的图形,如下表。上色大法好又多:1. 英文单词;2. 十六进制颜色代码;3. 十进制颜色代码。
参考:常用RGB配色表
top bottom right left:位置(可组合使用)
legend:标签
pch:图形
col:颜色
plot(NULL, xlim=0:1, ylim=0:1, xlab="", ylab="", xaxt="n", yaxt="n", bty="n")
legend("topleft", legend=c("子", "丑", "寅", "卯"), pch=15, col=c("red", "black", "blue", "purple"))
legend("center", legend=c("甲", "乙", "丙", "丁"), pch=17, col=c("#FFD700", "#ED9121", "#03A89E", "#FFC0CB"))
legend("bottomright", legend=c("上", "下", "左", "右"), pch=19, col=c(rgb(0,0,255,maxColorValue=255), rgb(11,23,70,maxColorValue=255), rgb(255,0,255,maxColorValue=255), rgb(255,69,0,maxColorValue=255)))
去掉框框,加大尺寸
pt.cex:图形大小
cex:标签大小
bty:图框
plot(NULL, xlim=0:1, ylim=0:1, xlab="", ylab="", xaxt="n", yaxt="n", bty="n")
legend("topleft", legend=c("子", "丑", "寅", "卯"), pch=15, col=c("red", "black", "blue", "purple"), pt.cex=2, cex=2, bty="n")
legend("center", legend=c("甲", "乙", "丙", "丁"), pch=17, col=c("#FFD700", "#ED9121", "#03A89E", "#FFC0CB"), pt.cex=2, cex=2, bty="n")
legend("bottomright", legend=c("上", "下", "左", "右"), pch=19, col=c(rgb(0,0,255,maxColorValue=255), rgb(11,23,70,maxColorValue=255), rgb(255,0,255,maxColorValue=255), rgb(255,69,0,maxColorValue=255)), pt.cex=2, cex=2, bty="n")
添加title,并调整位置
at:左右移动(top)
adj:左右移动
padj:上下移动
mtext("地支", at=0.1, cex=2, adj=0.5, padj=0.4, col="red")
mtext("天干", at=0.5, cex=2, adj=0.3, padj=4.5, col="red")
mtext("方位", at=0.95, cex=2, adj=0.5, padj=8, col="red")
参考
mtext