问题描述
通常情况下,要尽量减少情节中的墨水。我有一个多面情节( facet_wrap
),并且希望删除尽可能多的墨迹,同时保持可读性。我已经按照我的意愿设置了它,除非x和y轴不存在于小平面(子图)中,除非在最左边或底部。有了这么多的墨水,我相信眼睛需要这些线索,并且要求如何将x和y轴放在 facet_wrap
内的所有图中。下面是我的代码到目前为止,当前的输出和期望的输出(红线是所需的加入):
library( ggplot);库(网格)
ggplot(mtcars,aes(mpg,hp))+
geom_point()+
facet_wrap(〜carb)+
主题(面板。 grid = element_blank(),
panel.background = element_rect(fill =white,color =black),
panel.border = element_rect(fill = NA,color =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 )
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"))
Current Plot
Desired Plot
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!