End(Not run)例子
dat <- data.frame(Group = c("S1", "S1", "S2", "S2", "S3", "S3"),
Sub = c("A", "B", "A", "B","A", "B"),
Value = c(5,3,8,7,8,7))
dat #可通过调整数字顺序来实现左高右迪
ggplot(dat, aes(Group, Value)) +
geom_bar(aes(fill = Sub), stat="identity", position="dodge", width=.5) +
geom_signif(stat="identity",
data=data.frame(x=c(0.875,1.875,2.875), xend=c(1.125,2.125,3.125),
y=c(5.8,8.5,8.5), annotation=c("*** ", " ***", "***")),
aes(x=x,xend=xend, y=y, yend=y, annotation=annotation))
现在我想让B排前面
End(Not run)例子
dat <- data.frame(Group = c("S1", "S1", "S2", "S2", "S3", "S3"),
Sub = c("A", "B", "A", "B","A", "B"),
Value = c(5,3,8,7,8,7))
dat #可通过调整数字顺序来实现左高右迪
sub <- factor(dat$Sub,levels = c('B','A'))
ggplot(dat, aes(Group, Value)) +
geom_bar(aes(fill = sub), stat="identity", position="dodge", width=.5) +
geom_signif(stat="identity",
data=data.frame(x=c(0.875,1.875,2.875), xend=c(1.125,2.125,3.125),
y=c(5.8,8.5,8.5), annotation=c("*** ", " ", "")),
aes(x=x,xend=xend, y=y, yend=y, annotation=annotation))