本文介绍了覆盖网格而不是在其上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ggplot2图形,显示如下:



请注意,网格或轴线不会通过色带显示。处理此问题的一种方法是更改​​色带的 alpha 属性;然而,这可以使较浅的颜色太浅。



另一种想法是将丝网/轴线画在丝带的顶部而不是它们的下面。我怎样才能实现这个渲染顺序?



当然,这个问题可能会被问到ggplot2生成的任何图。但复制粘贴命令说明了这个问题,如下所示:

  ggplot(data.frame(x = sample( 1:100),y =样本(1:100)),aes(x = x,y = y))+ geom_point(size = 20)


解决方案

ggplot在 theme()中引入了一个选项, ,2015年6月18日。



只需添加到您的情节:

  +主题(
panel.background = element_rect( fill = NA),
panel.ontop = TRUE

ggplot 文档


I have a ggplot2 graph which appears as follows:

Notice that the grid or axis lines do not show through the ribbons. One way of dealing with this is to alter the alpha property of the ribbons; however, this can make the lighter colours too light.

An alternative idea would be to draw the grid/axis lines on top of the ribbons rather than beneath them. How can I achieve this render ordering?

Naturally, the question could be asked of any plot generated by ggplot2. But a copy-and-paste command that illustrates the issue is as follows:

 ggplot(data.frame(x=sample(1:100),y=sample(1:100)),aes(x=x,y=y))+geom_point(size=20)
解决方案

ggplot introduced an option in theme() that lets you do just that with pull number 993, on June 18, 2015.

Just add to your plot:

+ theme(
  panel.background = element_rect(fill = NA),
  panel.ontop = TRUE
)

There is an example in the ggplot docs.

这篇关于覆盖网格而不是在其上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:57