我想彻底去除标签为面,以产生一种火花效果,为观众的标签是不相关的,最好我能想出是:
library(MASS)
library(ggplot2)
qplot(week,y,data=bacteria,group=ID, geom=c('point','line'), xlab='', ylab='') +
facet_wrap(~ID) +
theme(strip.text.x = element_text(size=0))
所以,我可以摆脱(现为空)的完全strip.background允许更多的空间,为“迷你”?
或者替代地有更好的方式来获得大量的二进制值时间序列像这样的这种“ 火花 ”的效果?
对于ggplot V2.1.0或更高,使用element_blank()
以除去不需要的元素:
library(MASS) # To get the data
library(ggplot2)
qplot(
week,
y,
data = bacteria,
group = ID,
geom = c('point', 'line'),
xlab = '',
ylab = ''
) +
facet_wrap(~ ID) +
theme(
strip.background = element_blank(),
strip.text.x = element_blank()
)
在这种情况下,你想删除的元素被称为strip
。
替代使用ggplot GROB布局
在旧版本的ggplot
(V2.1.0)之前,条带文字占据了gtable布局行。
element_blank
删除文本和背景,但它不会删除该行所占用的空间。
此代码从布局中移除这些行:
library(ggplot2)
library(grid)
p <- qplot(
week,
y,
data = bacteria,
group = ID,
geom = c('point', 'line'),
xlab = '',
ylab = ''
) +
facet_wrap(~ ID)
# Get the ggplot grob
gt <- ggplotGrob(p)
# Locate the tops of the plot panels
panels <- grep("panel", gt$layout$name)
top <- unique(gt$layout$t[panels])
# Remove the rows immediately above the plot panel
gt = gt[-(top-1), ]
# Draw it
grid.newpage()
grid.draw(gt)
我使用GGPLOT2版本1和所需的命令改变了。 代替
ggplot() ... +
opts(strip.background = theme_blank(), strip.text.x = theme_blank())
您现在使用
ggplot() ... +
theme(strip.background = element_blank(), strip.text = element_blank())
欲了解更多详情请参阅http://docs.ggplot2.org/current/theme.html
由于靠近我可以告诉大家,桑迪的回答是正确的,但我认为这是值得一提的是,似乎有一个小的差异,没有一个方面的情节和去除小面的曲线的宽度的宽度。
它并不明显,除非你正在寻找它,但如果你一叠使用韦翰建议在他的著作中视情节布局,差异变得明显。
桑迪的更新答案似乎不错,但可能已经过时的更新ggplot? 从我可以告诉下面的代码(桑迪的原始回答的简化版本)抄录没有任何额外的空间Sean的原始图:
library(ggplot2)
library(grid)
qplot(week,y,data=bacteria,group=ID, geom=c('point','line'), xlab='', ylab='') +
facet_wrap(~ID) +
theme(strip.text.x = element_blank())
我使用ggplot 2.0.0。