本文介绍了突出显示ggplot2中感兴趣的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在vanilla plotting中,可以在 panel.first 参数中使用多边形调用 plot 突出显示背景区域。是否可以在 ggplot2 中做同样的事情?可以在保留网格线的情况下完成吗? 例如: #针对mtcars数据绘制hp和wt,突出显示hp / wt比率 panel.first = )), col =#d8161688,border = NA))) 解决方案是的,这可能与ggplot2。为了保持网格线的可见性,您可以使用alpha透明度。请注意,一般而言,geom和stats的应用顺序很重要。 tmp< - with(mtcars,data (x,c(0,0,max(wt)* 35),y = c(0,max(wt),max(wt)))) ggplot(mtcars,aes(hp,wt ))+ geom_polygon(数据= TMP,AES(X,Y),填充= #d8161688)+ geom_point() In vanilla plotting, it is possible to use a polygon call in the panel.first argument to plot to highlight a background region. Is it possible to do the same in ggplot2? Can it be done while preserving the gridlines?eg:# plot hp and wt for mtcars data, highlighting region where hp/wt ratio < 35with(mtcars,plot(hp,wt, panel.first=polygon(c(0,0,max(wt)*35),c(0,max(wt),max(wt)), col="#d8161688",border=NA))) 解决方案 Yes, that's possible with ggplot2. To preserve the visibility of grid lines you can use alpha transparency. Note that, in general, the order in which geoms and stats are applied matters.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() 这篇关于突出显示ggplot2中感兴趣的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!