Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的非分组箱线图间距_R - Fatal编程技术网

R中的非分组箱线图间距

R中的非分组箱线图间距,r,R,我正在尝试减小长方体图和y轴“类型”组之间的垂直间距。我似乎找不到我的问题复制到其他任何地方 bp <- ggplot(data = data, aes(x=type, y=time.from.sunset)) bp + geom_boxplot(width = 0.4, fill = "white") + coord_flip() + #switches x and y axes scale_y_reverse(limits=c(60,-20), breaks = c(60,

我正在尝试减小长方体图和y轴“类型”组之间的垂直间距。我似乎找不到我的问题复制到其他任何地方

bp <- ggplot(data = data, aes(x=type, y=time.from.sunset))

bp + geom_boxplot(width = 0.4, fill = "white") +
  coord_flip() + #switches x and y axes
  scale_y_reverse(limits=c(60,-20), breaks = c(60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0, -5, -10, -15, -20), labels = list(60, "", 50, "", 40, "", 30, "", 20, "", 10, "", "sunset", "", -10, "", -20)) +
  geom_point(size = 1.5, shape = 1) +
  labs(x = "Fly type\n", y = "\nTime from sunset (minutes)") +
  theme(strip.background = element_blank()) + 
  theme(panel.background = element_rect(fill="white")) +
  theme(axis.text.y = element_text(colour = "black", size = 14)) +
  theme(axis.text.x = element_text(colour = "black", size = 10)) + 
  theme(axis.title.x = element_text(colour = "black", size = 14)) + 
  theme(axis.line.x = element_line(colour = "black")) +
  theme(axis.ticks.y = element_blank()) + 
  geom_hline(yintercept=0, linetype="dashed", color = "red", size=0.5)

bp根据前面的答案,他要求使用以下参数

p + geom_boxplot(aes(fill = factor(gp)),position=position_dodge(1))

条形之间的间距由
width
参数控制,该参数已设置为0.4

用最少的示例重新创建您的问题:

library(ggplot2)

ggplot(iris, aes(x = Species, y = Sepal.Length)) +
  geom_boxplot(width = 0.4, fill = "white")+
  coord_flip()

更改
width=1
使它们之间没有间距:


正如@Henrik所指出的,如果您想更改条形的纵横比,可以更改图形设备的高度。这可以在
ggsave
参数中通过添加
height
选项轻松完成:

我尝试了这个方法,但没有对图形进行任何更改。我尝试过使用夸张的position_dodge()值,但仍然没有任何更改。这个答案不适用于此问题,因为箱线图没有分组。此外,如果您认为该问题以前已经回答过,请将该问题标记为重复,而不是将答案复制到stackoverflow,因此不知道它是如何工作的,或者更好的解决方案的规则是什么community@VishwasShrikhande,没问题,让您了解网站程序:)您可以在此处阅读更多有关标记罐的信息:更改图形设备的高度?请尽量减少您在问题中发布的代码量,并删除与您的问题无关的内容。这是代码疑难解答的重要部分,有助于让其他人更容易提供帮助。请查看这里的其他提示