r - 将 x 和 y 轴添加到所有 facet_wrap

标签 r ggplot2 facet facet-wrap

通常需要尽量减少绘图中的墨水。我有一个多面图( facet_wrap ),并希望尽可能多地去除墨水,同时保持可读性。我已经按照我的意愿进行了设置,除非在最左侧或最底部不存在构面(子图)的 x 和 y 轴。去除了这么多墨水后,我相信眼睛需要这些提示,我想知道如何在 facet_wrap 内的所有图中放置 x 轴和 y 轴。 .以下是迄今为止我的代码,当前输出和期望输出(红线是所需的添加项):

library(ggplot); library(grid)

ggplot(mtcars, aes(mpg, hp)) + 
    geom_point() + 
    facet_wrap(~carb) +
    theme(panel.grid = element_blank(),
        panel.background = element_rect(fill = "white", colour = "black"), 
        panel.border = element_rect(fill = NA, colour = "white"), 
        axis.line = element_line(),
        strip.background = element_blank(),
        panel.margin = unit(2, "lines"))

当前情节
enter image description here

想要的地块
enter image description here

最佳答案

最简单的方法是在每个绘图面板中添加段,

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + 
  facet_wrap(~carb) +
  theme_minimal() +
  annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf)+
  annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf)

example

关于r - 将 x 和 y 轴添加到所有 facet_wrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116518/

相关文章:

在 R 中重命名文件

r - 创建一个图表,图表下方有一个表格

r - 创建多列分面函数

r - ggplot2:在方面创建方面

r - 将多个图例与拼凑对齐

r - 如何修改由 scales 包生成的标签?

r - 使用 r markdown 和 knit 访问 R 脚本生成的数据

r - 在 R 中学习隐马尔可夫模型

r - "Multi-step"在 R 中使用 broom 和 dplyr 进行回归

r - 创建具有多个表达式的向量