我设立的箱图在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