目前我正在复制/更新海报演示的某些图形。我成功地复制了图形的颜色、值、条形样式和背景。但是缺少一个箭头标签,突出显示了值差异。我想知道是否有通过 ggplot (线条或箭头)的有用选项,值得付出努力 - 或者我必须用另一个图形软件绘制一些箭头......
这是我尝试做的:
这是我已经拥有的:
数据和代码:
weight <- c(113.2158, 108.5404, 98.75564, 93.93759)
sex <- c("m","m", "f","f")
time <- c("t0", "t1", "t0", "t1")
data <- data.frame(weight, sex, time)
library(ggplot2)
ggplot(data, aes(x = factor(sex), y = weight, group=time, fill=factor(time))) +
geom_bar(position="dodge", stat = "identity") +
theme(legend.position = c(0.8, 0.9),
axis.ticks = element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.background = element_blank(),
panel.grid.major.x = element_blank() ,
panel.grid.major.y = element_line( size=.1, color="grey" ),
legend.key = element_rect(size = 2),
legend.key.size = unit(1.5, 'lines')) +
guides(fill=guide_legend(title="time")) +
scale_fill_manual(values=c("#b6181f", "#f6b8bb"), labels=c("t0", "t1")) +
scale_x_discrete(labels = c("male, n = 57", "female, n = 133")) +
coord_cartesian(ylim = c(90,120)) +
scale_y_continuous(breaks=c(90,95,100,105,110,115,120)) +
geom_text(aes(x=factor(sex), label=round(weight, digits=2)), position = position_dodge(width = 1), vjust = -0.25) +
geom_line(aes(x=factor(sex), label=round(weight, digits=2)), position = position_dodge(width = 1), vjust = -0.25)
非常感谢您的想法。