我需要把标签的顶部/底部的酒吧,因为我的数字都是积极的和消极的(=双方的x轴)。
我一直在尝试使用vjust/hjust,到目前为止没有成功....
total_merged%>%
ggplot(aes(factor(NAPLAN_YEAR), value_add_sector_total, fill = model,
label = value_add_sector_total
)) +
geom_col(position = position_dodge(width = 0.75), width = 0.5) +
facet_grid(.~sector_report, switch = 'x') +
scale_fill_manual(NULL, values = c('#1e3763', '#bebebe'), labels = c("Base", "MLSH")) +
theme_minimal() +
geom_text(position = position_dodge(width = 0.75), hjust=0.5, vjust = 1.7, #angle = 90,
color="darkred")+
labs(title="",
x ="", y="System 'value add'")+
theme(legend.position = 'bottom',
aspect.ratio = 4/3,
strip.placement = 'outside',
panel.spacing.x = unit(0, 'mm'),
axis.title.x = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.y = element_blank(),
strip.text = element_text(face = 2),
legend.text=element_text(size=9),
legend.title=element_text(size=9),
axis.text= element_text(size = 9, colour = "black")
)
我的数据如下所示(前50个):
structure(list(value_add_sector_total = c(-1.38, -1.38, -1.38,
-1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38,
-1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38,
-1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38,
-1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38,
-1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38, -1.38,
-1.38, -1.38), NAPLAN_YEAR = c(2011, 2011, 2011, 2011, 2011,
2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011,
2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011,
2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011,
2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011,
2011), model = c("base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base", "base", "base",
"base", "base", "base", "base", "base", "base", "base", "base",
"base", "base", "base", "base")), row.names = c(NA, -50L), class = c("tbl_df",
"tbl", "data.frame"))
1条答案
按热度按时间5n0oy7gb1#
我不能复制你的代码与数据,你提供的,所以我将使用一个简单的数据框架。
在
aes()
中使用vjust()
,我们可以使用data.frame中的值,而无需创建虚拟数据: