Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

r - Overlay grid rather than draw on top of it

I have a ggplot2 graph which appears as follows:

ggplot2 graph without axis lines visible

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...