我正在尝试在此图表上添加数据标签。海军蓝色的数据标签很完美,但是对于天蓝色的数据条,我需要更高一些的黑色。我将代码和数据附加在底部。
ggplot(total.subs,aes(Date,value,fill = variable,label = value)) + #fill variable to make stack colors
scale_fill_manual("legend",values = c("sources" = "Navy blue","recipients" = "sky blue")) + #change colors for
geom_bar(stat = "identity",#stat identiy is for sum #source and recipient
position = position_stack(reverse = TRUE)) + # position stack is for reversing the colors + stacks
xlab("") + #leave the xlabel blank
ylab("") + #leave the ylabel blank
theme(axis.line=element_blank(),axis.text.y=element_blank(),axis.ticks=element_blank(),axis.title.y=element_blank(),panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),panel.grid.minor=element_blank(),plot.background=element_blank()
) + geom_text(size = 4,color = "white",position = position_stack(vjust =.95,reverse = T))
#geom_text(aes(label=variable),position=position_dodge(width=2),vjust=2) +
#geom_text(aes(label= value),position=position_dodge(width=5),vjust=5)
我的数据如下
structure(
list(
Date = c(
"Dec-09","Dec-10","Dec-11","Dec-12","Dec-13","Dec-14","Dec-15","Dec-16","Dec-17","Dec-18","YTD-2019","Dec-09","YTD-2019"
),variable = c(
"sources","sources","recipients","recipients"
),value = c(
189,872,1507,2181,2784,3125,4091,4775,5284,3723,3989,2,11,23,41,56,96,128,129,148,144,150
)
),class = c("spec_tbl_df","tbl_df","tbl","data.frame"),row.names = c(NA,-22L)
)