首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将x和y轴添加到所有facet_wrap

将x和y轴添加到所有facet_wrap
EN

Stack Overflow用户
提问于 2014-03-01 23:48:30
回答 5查看 42.3K关注 0票数 36

通常需要尽量减少绘图中的墨迹。我有一个刻面图(facet_wrap),并希望删除尽可能多的墨水,但保持可读性。我已经按照我想要的方式设置了它,除非在最左边或最下面,否则面(子图)的x和y轴是不存在的。在移除了这么多墨水之后,我相信眼睛需要这些提示,并且我在问如何在facet_wrap内的所有图中放置x和y轴。下面是到目前为止我的代码,当前的输出和deired的输出(红线是所需的插件):

代码语言:javascript
复制
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

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2014-03-02 01:15:54

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

代码语言:javascript
复制
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)

票数 33
EN

Stack Overflow用户

发布于 2014-03-02 00:20:36

这应该会大大简化事情:

代码语言:javascript
复制
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))

票数 39
EN

Stack Overflow用户

发布于 2018-03-20 22:00:15

以下是Thomas上面的回答-

您只需在facet_wrap中设置scales='free',并确保在scale_x_continuousscale_y_continuous中设置限制

代码语言:javascript
复制
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))
票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22116518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档