在香草绘图中,可以使用 polygon panel.first 论据 plot 突出显示背景区域。在中国也可以这样做吗 ggplot2
polygon
panel.first
plot
ggplot2
如:
# plot hp and wt for mtcars data, highlighting region where hp/wt ratio < 35 with(mtcars,plot(hp,wt, panel.first=polygon(c(0,0,max(wt)*35),c(0,max(wt),max(wt)), col="#d8161688",border=NA)))
是的,这在ggplot2中是可能的。要保持栅格线的可见性,可以使用alpha透明度。注意,一般来说,geom和stats的应用顺序很重要。
tmp <- with(mtcars, data.frame(x=c(0, 0, max(wt)*35), y=c(0, max(wt), max(wt)))) ggplot(mtcars, aes(hp, wt)) + geom_polygon(data=tmp, aes(x, y), fill="#d8161688") + geom_point()