首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改ggplot facet_wrap的facet标题格式

更改ggplot facet_wrap的facet标题格式
EN

Stack Overflow用户
提问于 2018-03-14 16:57:01
回答 1查看 2.1K关注 0票数 1

以下列数据生成的地块为例,使用以下代码:

代码语言:javascript
复制
library(dplyr)

dd<-data.frame(matrix(0,36,1))
dd$drug<-c("x","x","x","x","x","x","x","x","x","y","y","y","y","y","y","y","y","y","z","z","z","z","z","z","z","z","z","w","w","w","w","w","w","w","w","w")
dd$prev<-c(10,11,12,11,12,13,12,13,14,10,11,12,11,12,13,12,13,14,10,11,12,11,12,13,12,13,14,10,11,12,11,12,13,12,13,14)
dd$country<-c("a","a","a","b","b","b","c","c","c","a","a","a","b","b","b","c","c","c","a","a","a","b","b","b","c","c","c","a","a","a","b","b","b","c","c","c")
dd$year<-c(15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17,15,16,17)
dd<-dd[,-1]

dd <- dd %>%
  group_by(drug) %>%
  arrange(country) %>%
  ungroup()

ggplot(dd,aes(x=factor(year),y=prev,fill = factor(country,levels=c("a","b","c")),pos="dodge"))+
  geom_col(col = "black",size=0.25,pos=position_dodge(0.9)) +
  facet_wrap(~factor(drug, levels(factor(dd$drug))[c(2,1,3,4)]),strip.position="bottom",as.table=T,scales="free_x")+
  scale_fill_manual(values = c("a" = "white",
                           "b" = "lightskyblue2",
                           "c" = "lightpink"),
                guide = F)+
  scale_x_discrete(name="Year",labels=c(2015,2016,2017))+
  scale_y_continuous(name="Prevalence (%)")+
  theme_classic()

我想移动一下,但是找不到一种方法:

1-用小面标题2在每个小面的x轴上移动年份2-移除小面标题3周围的方框增加2个顶部和2个底部小面之间的空间。

结果应大致如下所示:

非常感谢!马可

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-14 17:28:14

检查?theme并读取strip.*的所有选项。与此相关的是位置和背景。对于间隔,有panel.spacing

代码语言:javascript
复制
ggplot(mtcars, aes(factor(am))) +
  geom_bar() +
  facet_wrap(~cyl, strip.position = "bottom", nrow = 2, scales = "free") +
  theme_classic() +
  theme(strip.placement = "outside",
        strip.background = element_blank(),
        panel.spacing.y = unit(2, "lines"))

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49283577

复制
相关文章

相似问题

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