完全删除facet_wrap标签

Sea*_*ean 62 graphics r ggplot2

我想完全删除刻面的标签以创造一种迷你效果,因为标签是不相关的观众,我能想到的最好的是:

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))
Run Code Online (Sandbox Code Playgroud)

那么我可以完全摆脱(现在是空白的)strip.background以便为"迷你图"留出更多空间吗?

或者,有没有更好的方法来获得像这样的大量二进制值时间序列的" 迷你 "效果?

San*_*att 95

对于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()
)
Run Code Online (Sandbox Code Playgroud)

在这种情况下,将调用您要删除的元素strip.

没有面板标题的ggplot2数字


替代使用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)
Run Code Online (Sandbox Code Playgroud)


hib*_*ado 24

我正在使用ggplot2版本1,并且所需的命令已更改.代替

ggplot() ... + 
opts(strip.background = theme_blank(), strip.text.x = theme_blank())
Run Code Online (Sandbox Code Playgroud)

你现在用

ggplot() ... + 
theme(strip.background = element_blank(), strip.text = element_blank())
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅http://docs.ggplot2.org/current/theme.html


Nic*_*ich 8

桑迪的更新答案似乎不错,但是,可能已因 ggplot 的更新而过时了?据我所知,以下代码(桑迪原始答案的简化版本)在没有任何额外空间的情况下再现了肖恩的原始图:

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())
Run Code Online (Sandbox Code Playgroud)

我正在使用 ggplot 2.0.0。