亲爱的,我想在ggplot2中的栏之间添加空格.本页提供了一个解决方案:http://www.streamreader.org/stats/questions/6204/how-to-increase-the-space-between-the-bars-in-a-bar-plot-in-ggplot2.但是,此解决方案不是使用x轴分组的因子级别,而是创建一个数字序列x.seq,以手动放置条形,然后使用width()参数对它们进行缩放.但是,当我使用x轴的因子级别分组时,width()不起作用,如下例所示.
library(ggplot2)
Treatment <- rep(c('T','C'),each=2)
Gender <- rep(c('M','F'),2)
Response <- sample(1:100,4)
df <- data.frame(Treatment, Gender, Response)
hist <- ggplot(df, aes(x=Gender, y=Response, fill=Treatment, stat="identity"))
hist + geom_bar(position = "dodge") + scale_y_continuous(limits = c(0,
100), name = "")
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何获得与链接示例中相同的效果,但在使用因子级别分组时?
干杯,
亚伦
我想在R使用上方/下方绘制多个箱图,而不是彼此相邻ggplot2.这是一个例子:
library("ggplot2")
set.seed(1)
plot_data<-data.frame(loc=c(rep(1,200),rep(2,100)),
value=c(rnorm(100,3,.5),rnorm(100,1,.25),2*runif(100)),
class=c(rep("A",100),rep("B",100),rep("C",100)))
ggplot(plot_data,aes(x=loc,y=value,group=class)) +
geom_boxplot(fill=c("red","green","blue"))
Run Code Online (Sandbox Code Playgroud)
这导致以下情节:

如您所见,蓝色框图以其loc值(2.0)为中心,而红色和绿色仅具有宽度的一半,并且绘制在其共享loc值(1.0)的左侧和右侧.我想让它们都与蓝色宽度相同,并将它们直接绘制在彼此之上.
我怎样才能做到这一点?
请注意,我确信箱形图对于我要显示的数据不会重叠,就像它们不适用于给定的示例数据一样.