打印ggplot y轴值为10万 [英] Print ggplot y axis values in 10 thousands

查看:189
本文介绍了打印ggplot y轴值为10万的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在修改我的y轴值时遇到了一些麻烦。



这是我的df:

 年份< -c( 1997,1997,1997,1998,1998,1998,1999,1999,1999,2000,2000,2000 $ b类型< -c(导出,导入,生产,导出,导入,生产,导出,导入,生产,导出 ,生产)
金额<-c(12063595,19465000,38591914,14929732,20941620,42570725,33598846,30533486,62633597,39755626,30129958,49493053)
df <-data。 (年,类型,金额)

这是我制作的图表:


$ b $

  ggplot(data = df,aes(x = Years,y = Amount,group = Type,color = 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(color = guide_legend(override.aes = list(size = 3)))+
theme(legend.title = element_blank(),
legend.position =top,
legen d.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))

正如你所看到的,我有很高的数字(最高= 62,633,597),现在它们被科学地显示出来(6e + 07)。
我想在标签中显示10万个的值,我完全不知道是否有办法做到这一点。

解决方案

如果您将第一行更改为

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

'会得到这个:

这是你想要的吗?



请注意,我必须删除 scale_colour_manual(values = cbPalette)仅仅是因为我不知道什么包 cbPalette 来自...




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.

解决方案

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...

这篇关于打印ggplot y轴值为10万的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆