Print ggplot y axis values in 10 thousands

2019-06-25 12:52发布

问题:

I am having some trouble changing my y-axis values.

This is my df:

Years <-c("1997","1997","1997", "1998","1998","1998", "1999", "1999","1999","2000", "2000", "2000")
Type <-c("Export","Import", "Production","Export","Import", "Production", "Export","Import", "Production","Export","Import", "Production")
Amount <- c(12063595,19465000,38591914,14929732,20941620,42570725,33598846,30533486,62633597,39755626,30129958,49493053)
df <-data.frame(Years, Type, Amount)

And this is the graph I have produced:

ggplot(data=df, aes(x=Years, y=Amount, group=Type, colour=Type)) +
  geom_line(size=1.1) +
  scale_colour_manual(values=cbPalette)+
  theme_bw()+
  ylab("Timber   [in 10,000 m3(r)]") +
  xlab("Years")  +
  expand_limits(y=0) + guides(colour = guide_legend(override.aes = list(size=3)))+
  theme(legend.title=element_blank(), 
        legend.position="top",
        legend.text = element_text(size=20),
        axis.text.x  = element_text(size=20), axis.title.x=element_text(size=20),
        axis.text.y  = element_text(size=20), axis.title.y=element_text(size=20))

As you can see I have very high numbers (highest = 62,633,597) and right now they are displayed scientifically (6e+07). I would like to display the values "in 10 thousands" as indicated in the label and I have absolutely no idea if there is a way to do that.

回答1:

If you change the first line to

ggplot(data=df, aes(x=Years, y=Amount / 10000, group=Type, colour=Type))

then you'll get this:

Is this what you wanted?

Note that I had to remove scale_colour_manual(values=cbPalette) only because I don't know what package cbPalette comes from...



标签: r ggplot2 axis