尝试使用pch绘制一个图例,我的理解是这些应该被填充,但似乎不是这样。这是windows图形的问题吗?
legend(36, 79,
legend = c(expression("a"["a"]), expression("b"["b"]), expression("c"["c"])),
pch = c(21, 8, 24), col = c(grey(0.1), grey(0.3), grey(0.5)),
cex = 1.3, bty = "n"
)
答案 0 :(得分:3)
我们需要pt.bg
参数填写:
见下面的例子:
#dummy data
set.seed(123)
df <- data.frame(x=runif(10),y=runif(10),
colour=rep(c("blue","green"),5),
background=rep(c("grey30", "grey70"),5),
shape=rep(c(21,24),5),stringsAsFactors = FALSE)
#plot
plot(df$x,df$y,col=df$colour,bg=df$background,pch=df$shape,cex=2)
points(x=0.5,y=0.5,pch=8,col="red",cex=2)
#add legend, pt.bg is need to fill in the background of the shape
legend(0.01,0.5,
legend = c(expression("LBM"["MR-AC"]),
expression("LBM"["Formula"]),
expression("LBM"["MR-AC corrected"])),
pch = c(21,24,8),
col = c("blue","green","red"),
pt.bg = c("grey30","grey70"),
cex=2)