2016-10-27 143 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

沒錯,謝謝。 –