-->

如何提高facet_grid箱线图一ggplot内缘?(How to increase the in

2019-09-26 15:33发布

我设立的箱图在GGPLOT2提出这些facet_grid ,我想增加内缘。

不幸的是,我不能够提高到面的边框之间的距离。

我怎么能增加内缘(左,右)的蓝色箭头指示?

require(ggplot2)
dat <- rbind(data.frame(approach=1,product=1,value=seq(1,20,0.5)), 
             data.frame(approach=1,product=2,value=seq(5,15,0.3)), 
             data.frame(approach=1,product=3,value=seq(5,17,0.2)), 
             data.frame(approach=2,product=1,value=seq(1,13,0.3)), 
             data.frame(approach=2,product=2,value=seq(3,18,0.5)), 
             data.frame(approach=2,product=3,value=seq(4,25,0.7)), 
             data.frame(approach=3,product=1,value=seq(1,15,0.6)), 
             data.frame(approach=3,product=2,value=seq(3,16,0.5)), 
             data.frame(approach=3,product=3,value=seq(1,10,0.1)))

gg1 <- ggplot(dat, aes(group =product, y = value)) + 
  geom_boxplot() + 
  ylab("size (cm)")+ 
  theme(panel.spacing = unit(0.1, 'lines')) + 
  theme(plot.background = element_rect(fill ="lightgrey" )) +
  scale_fill_grey(start = 0.0, end = 1) +
  theme_bw()+ 
  xlab("") +   
  facet_grid(cols=vars(approach)) +
  theme(axis.text.x = element_text(colour="black")) + 
  theme(axis.text.y=element_text(colour="black"))+ 
  theme(panel.spacing=unit(0,"lines")) + 
  guides(fill=guide_legend(title="Products")) + 
  theme(plot.background = element_rect(fill ="lightgrey" ))

gg1

此外,如何将它用于离散规模工作?

require(ggplot2)
dat <- rbind(data.frame(approach=1,product=1,value=seq(1,20,0.5)), 
             data.frame(approach=1,product=2,value=seq(5,15,0.3)), 
             data.frame(approach=1,product=3,value=seq(5,17,0.2)), 
             data.frame(approach=2,product=1,value=seq(1,13,0.3)), 
             data.frame(approach=2,product=2,value=seq(3,18,0.5)), 
             data.frame(approach=2,product=3,value=seq(4,25,0.7)), 
             data.frame(approach=3,product=1,value=seq(1,15,0.6)), 
             data.frame(approach=3,product=2,value=seq(3,16,0.5)), 
             data.frame(approach=3,product=3,value=seq(1,10,0.1)))

dat$product<-as.factor(dat$product)

gg1<-ggplot(dat, aes(x =product, y = value)) +
  geom_boxplot() + 
  ylab("size (cm)")+ 
  theme(panel.spacing = unit(0.1, 'lines')) +
  theme(plot.background = element_rect(fill ="lightgrey" )) +
  scale_fill_grey(start = 0.0, end = 1) +  
  theme_bw()+ xlab("") + 
  facet_grid(cols=vars(approach)) +
  theme(axis.text.x = element_text(colour="black")) +
  theme(axis.text.y=element_text(colour="black"))+ 
  theme(panel.spacing=unit(0,"lines")) + 
  guides(fill=guide_legend(title="Products")) + 
  theme(plot.background = element_rect(fill ="lightgrey" ))

gg1

Answer 1:

你在看的部分是由秤,不面或主题利润率控制。

下面的任一会工作。 他们的研究结果是在这种情况下,类似的,因为你的x值范围是在附近(-1, 1) 更一般地,抬头看帮助文件?expand_scale的乘法与添加剂扩张因素的例子

gg1 + scale_x_continuous(expand = c(0.2, 0)) # expand scales by a multiple of 20%

gg1 + scale_x_continuous(expand = c(0, 0.2)) # expand scales by an addition of 0.2



文章来源: How to increase the inner margin of a ggplot boxplot in facet_grid?