将 x 和 y 轴添加到所有 facet_wrap [英] Add x and y axis to all facet_wrap

查看:26
本文介绍了将 x 和 y 轴添加到所有 facet_wrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

It is often desirable to minimize ink in a plot. I have a faceted plot (facet_wrap) and would like to remove as much ink as possible yet maintain readability. I have set it up as I'd like except the x and y axis is not present for the facets (subplots) unless on the far left or bottom. With so much ink removed I believe the eye needs these cues and am asking how to put the x and y axis in all plots within a facet_wrap. Below is my code thus far, the current output and the deired output (red lines are the desired add in):

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"))

当前剧情

想要的情节

推荐答案

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

easiest way would be to add segments in each plot panel,

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)

这篇关于将 x 和 y 轴添加到所有 facet_wrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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