【问题标题】:Is there a way to remove gridlines from an effect_plot?有没有办法从 effect_plot 中删除网格线?
【发布时间】:2019-06-24 18:04:35
【问题描述】:

为了清理图形,我试图从使用 r 中的“effect_plot”函数创建的图形中删除网格线,但我所做的任何事情似乎都不起作用

我相当了解使用 r,所以我可能不知道所有的技巧,但我所做的所有技巧似乎都不适合我,或者我只是把代码弄错了。我似乎找不到直接删除 effect_plot 函数中的网格线的方法。

我使用了来自https://rdrr.io/cran/jtools/man/gridlines.html 的“drop_gridlines(x = TRUE, y = TRUE, minor.only = FALSE)”

我什至尝试使用 https://cran.r-project.org/web/packages/jtools/jtools.pdf 中的 theme_apa 更改主题

这是我目前没有尝试删除网格线的代码:

model1

effect_plot(model1, pred = NumPolls, intterval = TRUE, x.label = "传粉者数量 (花密度 = 29-894)", y.label = "总番茄花粉", rescale.axis=F, int .type = "信心", plot.points = TRUE) The resulting plot from the above code

我希望有一些方法可以删除网格线,或者在 R 中根本没有办法这样做,需要在 illustrator 中完成。

【问题讨论】:

    标签: r gridlines


    【解决方案1】:

    因为effect_plot()创建了一个ggplot对象,所以可以重新主题化。

    这里我将所有网格线(x、y、major 和 minor)设置为空白:

    effect_plot(model1, pred = NumPolls, intterval = TRUE, x.label = "Number of Pollinators (Floral Density= 29-894)", y.label = "Total Tomato Pollen", rescale.axis=F, int.type = "confidence", plot.points= TRUE) + 
    theme(panel.grid = element_blank()))
    

    更多组件请参见heretheme()

    【讨论】:

    • 请参阅 here 以获取 element_line() 参数。
    • 非常感谢!我现在的另一个问题是添加轴线。除了上面的代码,我还添加了“...+ theme(axis.line= element_line())”,但没有出现任何内容。我看过另一篇关于此的帖子,但他们不接受任何答案,并且发布的帖子并没有解决我的问题。
    • 没错,它适用于我在 R 3.6.0 上使用 ggplot 3.2.0。试试theme(axis.line.x = element_line(), axis.line.y = element_line())
    猜你喜欢
    • 2010-10-29
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多