简体   繁体   中英

Manipulating Axes in ggplot2 in R

I have the following dataframe and I am using ggplot to plot the ind vs values.

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

stats

    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

The plot in y-axis is in the form of 0e+00, 1e+08, 2e+08 and so on but instead I need it in the form of 100M(hundred million), 200M(two hunderd million) etc marks. How can I get the desired axes in ggplot?

You may try

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM