通過下面的代碼,我在下面生成了一個分組條形圖:
df <- data.frame(Person = c("Mr.A","Mr.B"), Cats = c(3,4), Dogs = c(1,2))
data.m <- melt(df, id.vars='Person')
ggplot(data.m, aes(Person, value))
geom_bar(aes(fill = variable), width = 0.4, position = position_dodge(width=0.5), stat="identity")
geom_text(
aes(x = Person, y = value, label=value),
position = position_dodge(width=1),
# position = 'dodge',
# hjust=-1,
vjust=-0.25)
theme(legend.position="top",
legend.title = element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank())

現在我的問題是如何調整每個條形列中間的文本(如上圖中的箭頭所示),我嘗試了引數:position=position_dodge(width=1),和position='dodge',似乎不起作用。有人可以幫忙嗎?謝謝。hjust=-1hjust=1
參考:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436085.html
