简体   繁体   English

如何增加具有离散 x 轴的箱线图 (ggplot2) 之间的距离 - position_dodge?

[英]How to increase the distance between boxplots (ggplot2) which have discrete x-axis - position_dodge?

I am trying to change the distance between boxplots in a ggplot2 figure.我正在尝试更改 ggplot2 图中箱线图之间的距离。 I have boxplots which show the data for different categories of products.我有箱线图,显示不同类别产品的数据。 The categories (x-axis) are discrete variables.类别(x 轴)是离散变量。 I tried position_dodge which did not affect the distance between the boxplots.我尝试了 position_dodge ,它不影响箱线图之间的距离。 It worked when the x-axis was a continuous variable.当 x 轴是连续变量时,它起作用。

Which command would increase the distance between the boxplots when x-axis is discrete?当 x 轴是离散的时,哪个命令会增加箱线图之间的距离?

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, width = 4)) +
     geom_boxplot(position=position_dodge(1))
gg1

在此处输入图片说明

Not entirely clear but...Do you want to play with width ?不完全清楚但是...你想玩width吗?

geom_boxplot(width=0.5) produces geom_boxplot(width=0.5)产生

在此处输入图片说明

geom_boxplot(width=0.1) produces geom_boxplot(width=0.1)产生

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM