2016-10-27 181 views
0
df.test <- data.frame(val=c(0.55,0.42,-0.05),name=letters[1:3], 
desc='This is  the description of values' 

p <- ggplot(df.test, aes(name, val, label = desc)) + 
    geom_bar(stat = "identity", col = 'black', fill = 'lightgreen') + 
    labs(title = "Test", x = " ", y = "value", fill = "") + 
    theme_bw() + 
    guides(fill = FALSE) 

p + geom_text(angle = 90, size = 8, hjust = 1.25, position = position_dodge(width = 0.9)) 

这将生成以下情节:对齐文本GGPLOT2

enter image description here

我要对齐的文本,并迫使它在每个图表的月初开始,使所有的它们可以被看到(如果它不在小图表之外,那么可以)。我怎样才能做到这一点?

回答

1

这是你在找什么?

p <- ggplot(df.test,aes(name,val,label=desc))+ 
     geom_bar(stat="identity",col='black',fill='lightgreen')+ 
     labs(title = "Test", x = " ", y = "value",fill = "")+ 
     theme_bw()+ 
     guides(fill=FALSE) 
    p+geom_text(angle=90,size=8,hjust=0,aes(x=name,y=rep(0,nrow(df.test)),label=desc),inherit.aes=F) 

enter image description here

+0

没错,谢谢。 –