不同元素的ggplot字体大小 [英] ggplot font size for different elements

查看:127
本文介绍了不同元素的ggplot字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在创建ggplot图之后,我可以使用 theme_get()来返回所有主题元素的细节。这在计算诸如 strip.text.x 之类的东西时非常有用。但是我有两件事情我无法弄清楚:



1)在下面的ggplot图形中,代表短语木材百分比被土拨鼠夹住,因为我想将它调整为更大的字体:

解决方案

对于(2)你想要的是使用格式化程序:

  dat < -  data.frame(x = 1:10,y = 1: 10)

#For ggplot2 0.8.9
ggplot(dat,aes(x = x / 10,y = y / 10))+
geom_point()+
scale_x_continuous(formatter =percent)

#For ggplot2 0.9.0
ggplot(dat,aes(x = x / 10,y = y / 10))+
geom_point()+
scale_x_continuous(labels = percent_format())


I know that after I create a ggplot graph I can use theme_get() to return detail of all the theme elements. This has been very helpful in figuring out things like strip.text.x and the like. But I have two things I can't figure out:

1) In the following ggplot graphic, what is the name of the theme item representing the phrase "Percent of wood chucked by the woodchuck" as I want to resize it to a larger font:

2) How do I reformat the y axis labels to read 10%, 20, ... instead of .1, .2, ...

解决方案

For (2) what you want is to use a formatter:

dat <- data.frame(x=1:10,y=1:10)

#For ggplot2 0.8.9    
ggplot(dat,aes(x = x/10,y=y/10)) + 
    geom_point() +
    scale_x_continuous(formatter = "percent")

#For ggplot2 0.9.0    
ggplot(dat,aes(x = x/10,y=y/10)) + 
    geom_point() +
    scale_x_continuous(labels = percent_format())

这篇关于不同元素的ggplot字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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