通常需要尽量减少绘图中的墨迹。我有一个刻面图(facet_wrap
),并希望删除尽可能多的墨水,但保持可读性。我已经按照我想要的方式设置了它,除非在最左边或最下面,否则面(子图)的x和y轴是不存在的。在移除了这么多墨水之后,我相信眼睛需要这些提示,并且我在问如何在facet_wrap
内的所有图中放置x和y轴。下面是到目前为止我的代码,当前的输出和deired的输出(红线是所需的插件):
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
发布于 2014-03-02 01:15:54
最简单的方法是在每个绘图面板中添加线段,
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)
发布于 2014-03-02 00:20:36
这应该会大大简化事情:
library('ggthemes')
ggplot(mtcars, aes(mpg, hp)) + geom_point() + facet_wrap(~carb, scales='free') +
theme_tufte() + theme(axis.line=element_line()) +
scale_x_continuous(limits=c(10,35)) + scale_y_continuous(limits=c(0,400))
发布于 2018-03-20 22:00:15
以下是Thomas上面的回答-
您只需在facet_wrap
中设置scales='free'
,并确保在scale_x_continuous
和scale_y_continuous
中设置限制
ggplot(mtcars, aes(mpg, hp)) + geom_point() + facet_wrap(~carb, scales='free') +
scale_x_continuous(limits=c(10,35)) + scale_y_continuous(limits=c(0,400))
https://stackoverflow.com/questions/22116518
复制相似问题