将ggplot条形标签与绘图轴对齐

时间:2018-06-26 17:54:52

标签: r ggplot2

我希望条形图标签在y轴上从0开始。现在,我可以在小节的末尾调整它们,但这不是我想要的。

data.df <- data.frame(Proportions=c(.4,.2,.25,.4,.12,.16),Name=c("Label one","Label two","Label three","Label one","Label two","Label three"),group=c("group.one","group.one","group.one","group.two","group.two","group.two"))
 ex.plot <-
   ggplot(data.df, aes(x=Name,y=Proportions,fill=group))+
   geom_bar(stat='identity')+
   xlab(NULL)+
   ylab(NULL)+
   scale_y_continuous(limits=c(0,1))+
   scale_fill_manual(values=c("#EDA45E","#DB7365"))+
   guides(fill=FALSE)+
   geom_text(aes(label=Name),angle=90,hjust=1)+
   theme_bw()+
   theme(strip.text.x = element_blank())+
   theme(panel.grid.major.x = element_blank(),axis.text.x=element_blank(),
         axis.title.y = element_blank())+
   facet_wrap(~group,nrow=1)

 plot(ex.plot)

Not what I want:

2 个答案:

答案 0 :(得分:0)

y的美感映射到0

...
geom_text(aes(label = Name, y = 0), angle = 90, hjust = 0) +
...

答案 1 :(得分:0)

geom_text(aes(label=Name, y=0), angle=90, hjust=0)

hjust=0表示左对齐。