【发布时间】:2022-01-06 13:06:35
【问题描述】:
我有一个 100% 堆积条形图,它显示 3 种类型的变量。我已经设置了一个示例数据库,因此我可以更轻松地创建图表。
我已经用我需要的颜色和信息调整了图表。但我无法独立定位标签。这是当前代码和输出。
代码:
(empilhado<-ggplot(dfm, aes(y = Year, x = abs(value), fill = variable)) +
scale_x_continuous(sec.axis = sec_axis(trans = ~.*1, name="Trab."), expand=expansion(mult=c(0,0.05)))+
geom_col(data = rotulo, aes(y = Year, x=abs(trabalho), fill=NULL), width = .7, colour="black", lwd=0.1, position = "fill", orientation = "y") +
geom_label(data = rotulo, aes(y= Year, x = abs(trabalho), fill=NULL, label=paste(format(round(trabalho, digits=0), nsmall=0, decimal.mark=",", big.mark="."),
format(round(aprovado, digits=0), nsmall=0, decimal.mark=",", big.mark="."))
), color="black", size=4, position = position_fill(vjust=1.06)) +
geom_col(width = .7, colour="black", lwd=0.1, position = "fill", orientation = "y") +
geom_text(aes(label=format(round(value, digits=0), nsmall=0, decimal.mark=",", big.mark=".")),
size=4, color="white", position = position_fill(vjust=0.5)) +
theme(panel.grid.major = element_line(colour = "gray90",size=0.75), panel.grid.minor = element_line(colour = "gray90",size=0.75),
legend.position="top", axis.text.x = element_blank(), axis.ticks.x = element_blank(),
axis.title.x = element_blank(), panel.background = element_blank())+
scale_fill_manual(values = c("#000000","tomato","blue"))
输出:
现在怎么样了? Position_fill(vjust=0.5),所以所有标签都在其各自的栏内居中。
我想要什么?为了能够在左侧设置“Marionete”标签的位置(就像 vjust=0 一样),保持“Pedido”标签原样(在“Pedido”堆叠条的中心)并放置“右侧的 Fatura' 标签(就像 vjust=1 一样)。
提前致谢!
【问题讨论】:
标签: r ggplot2 label position geom-text