加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

ggplot2--Titles(设置标题)

(2012-07-05 21:47:12)
标签:

ggplot2

titles

ggplot2标题

杂谈

分类: ggplot2
本节主要涉及到如何在ggplot2中设置或修改标题(Titles)

问题:
    在ggplot2中设置或修改标题
解决方案:
画一个没有标题的图, R代码如下:

 #加载ggplot2包
stopifnot(require(ggplot2))                                
 # 画一个boxplot并设置填充颜色为grey
bp = ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot(fill="grey") 
# 打开画图结果(或bp)
print(bp)                                                    
  
添加标题(title)
bp + opts(title="Plant growth")
# If the title is long, it can be split into multiple lines with \n
bp + opts(title="Plant growth with\ndifferent treatments")

# Reduce line spacing and use bold text
bp + opts(title="Plant growth with\ndifferent treatments") + 
opts(plot.title = theme_text(size=14, lineheight=.8, face="bold"))

写成一行如下, 同时添加xlab和ylab:
ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot(fill="grey") + opts(title="Plant growth\ndifferent treatment") + xlab("Growth") + ylab("Weight")

在R命令上中通过help(opts)查看有关opts更多的帮助和示例.

Reference

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有