2014-12-20 81 views
1

我有以下數據框,我使用ggplot來繪製ind與值。在R ggplot2操縱軸

ggplot(data=stats,aes(x=ind,y=values,fill=ind))+geom_bar(stat="identity")+coord_flip()+scale_fill_brewer() 

統計

values  ind 
1 238970950 testdb_i 
2 130251496 testdb_b 
3 314350612 testdb_s 
4 234212341 testdb_m 
5 222281421 testdb_e 
6 183681071 testdb_if 
7 491868567 testdb_l 
8 372612463 testdb_p 

在y軸的曲線圖是在0E + 00的形式,1E + 08,2E + 08等,而是我需要它在100M形式(億),200M(兩萬億)等標誌。我怎樣才能在ggplot中獲得所需的軸?

回答

4

您可以嘗試

ggplot(data=stats,aes(x=ind,y=values,fill=ind))+ 
geom_bar(stat="identity")+ 
coord_flip()+ 
scale_fill_brewer()+ 
scale_y_continuous(labels=function(x) paste0(x/1e6,"M"))