ggplot:如何更改构面标签? [英] ggplot: How to change facet labels?

查看:205
本文介绍了ggplot:如何更改构面标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了下面的ggplot命令:

I have used the following ggplot command:

ggplot(survey,aes(x=age))+stat_bin(aes(n=nrow(h3),y=..count../n), binwidth=10)
  +scale_y_continuous(formatter = "percent", breaks=c(0, 0.1, 0.2)) 
  + facet_grid(hospital ~ .) 
  + opts(panel.background = theme_blank()) 



<生产

to produce

然而,我想将 facet 标签更改为更短的标签(如Hosp 1,Hosp 2 ...),因为它们现在太长而且看起来拥挤(增加图形的高度不是一个选项,它会占用太多的文档空间)。我查看了 facet_grid 帮助页面,但无法弄清楚。

I'd like to change the facet labels, however, to something shorter (like Hosp 1, Hosp 2...) because they are too long now and look cramped (increasing the height of the graph is not an option, it would take too much space in the document). I looked at the facet_grid help page but cannot figure out how.

推荐答案

使用类似于以下的方式更改基础级别名称:

Change the underlying factor level names with something like:

# Using the Iris data
> i <- iris
> levels(i$Species)
[1] "setosa"     "versicolor" "virginica" 
> levels(i$Species) <- c("S", "Ve", "Vi")
> ggplot(i, aes(Petal.Length)) + stat_bin() + facet_grid(Species ~ .)

这篇关于ggplot:如何更改构面标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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