通常需要尽量减少绘图中的墨水。我有一个多面图( 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"))
当前情节
想要的地块
最佳答案
最简单的方法是在每个绘图面板中添加段,
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)
关于r - 将 x 和 y 轴添加到所有 facet_wrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116518/