ggplot2中的主题操作:更改x和y网格线 [英] Theme manipulation in ggplot2: altering x and y grid lines

查看:1720
本文介绍了ggplot2中的主题操作:更改x和y网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用主题操作ggplot中的虚线和虚线网格线的间距和大小?如下图:

  p + l + opts(panel.grid.major = theme_line(color ='black',linetype = 'bash'),
panel.grid.minor = theme_line(color = NA),
panel.background = theme_rect(color ='white'))



我想在虚线和虚线网格线之间更改间距(如在Illustrator中)。


$ b $另外,有没有人知道x轴和y轴的网格线是否可以单独处理?例如,我想在这个例子中关闭x轴网格线。

我已经看到了使用vline和hline的操作(),但是如果可能的话,不要每次都要硬编码。



解决方案

您可以使用 lty 的威力。请参阅?par



中的行类型规范。 b
$ b

  qplot(1:5,1:5)+ opts(panel.grid.major = theme_line(linetype =2925))

至于第二个问题,此时不能单独指定v和h行。

  qplot(1:5,1:5)
grid .edit(panel.grid.major.x.polyline,grep = TRUE,gp = gpar(lty =5195))
grid.edit(panel.grid.major.y.polyline, grep = TRUE,gp = gpar(lty =33))


Is it possible to manipulate the spacing and size of dashed and dotted grid lines in ggplot using the themes? The following plot:

p + l + opts(panel.grid.major = theme_line(colour = 'black', linetype = 'dashed'), 
             panel.grid.minor = theme_line(colour = NA), 
             panel.background = theme_rect(colour = 'white'))

I'd like to change the spacing (such as in Illustrator) between dashed and dotted grid lines.

Additionally, does anyone know if the x-axis and y-axis grid lines can be manipulated separately? For instance, I want to turn off the x-axis grid lines in this example.

I have seen manipulation using vline and hline (Add a dotted vertical line on certain x-axis values using ggplot), but don't want to have to hard code that each time if possible.

解决方案

You can use the power of lty. see Line Type Specification in ?par.

example:

qplot(1:5, 1:5) + opts(panel.grid.major = theme_line(linetype = "2925"))

As for the second question, at this time you cannot specify the v and h lines separately.
Here is a quick and dirty hack:

qplot(1:5, 1:5)
grid.edit("panel.grid.major.x.polyline", grep = TRUE, gp = gpar(lty = "5195"))
grid.edit("panel.grid.major.y.polyline", grep = TRUE, gp = gpar(lty = "33"))

这篇关于ggplot2中的主题操作:更改x和y网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆