Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 刻面时如何在绘图下方显示条形标签?_R_Ggplot2 - Fatal编程技术网

R 刻面时如何在绘图下方显示条形标签?

R 刻面时如何在绘图下方显示条形标签?,r,ggplot2,R,Ggplot2,条带似乎始终位于由ggplot2创建的绘图上方。它们可以移到地块下方吗 例如: library(ggplot2) qplot(hwy, cty, data = mpg) + facet_grid( . ~ manufacturer) 在顶部显示车辆信息。可以在底部显示吗? < P> 更新:< /强>使用 GGPROT2版本2.1.0,考虑使用 Swite=“x”< /代码>。有关详细信息,请参见?刻面网格 使用gtable功能,可以轻松移动铝带。(另一个版本请参见-交换x轴和带) 库(ggp

条带似乎始终位于由ggplot2创建的绘图上方。它们可以移到地块下方吗

例如:

library(ggplot2) 
qplot(hwy, cty, data = mpg) + facet_grid( . ~ manufacturer)

在顶部显示车辆信息。可以在底部显示吗?

< P> <强>更新:< /强>使用<代码> GGPROT2版本2.1.0,考虑使用<代码> Swite=“x”< /代码>。有关详细信息,请参见
?刻面网格

使用
gtable
功能,可以轻松移动铝带。(另一个版本请参见-交换x轴和带)

库(ggplot2)
图书馆(gtable)
图书馆(网格)

p一段时间后,ggplot邮件列表中也提出了类似的问题。谢谢我没有意识到这是如此困难。(另一个否定的回答)如果你像我一样,想要在x轴上方粘贴条形标签,你可以使用
gt=gtable\u add\u grob(gt,stripGrob,t=max(panels$b)+1,l=min(panels$l),r=max(panels$r))
来代替桑迪的做法
library(ggplot2)
library(gtable)
library(grid)

p <- ggplot(mpg, aes(hwy, cty)) + geom_point() + facet_grid( . ~ manufacturer) +
     theme(strip.text.x = element_text(angle = 90, vjust = 1),
           strip.background = element_rect(fill = NA))

# Convert the plot to a grob
gt <- ggplotGrob(p)

# Get the positions of the panels in the layout: t = top, l = left, ...
panels <-c(subset(gt$layout, grepl("panel", gt$layout$name), select = t:r))

# Add a row below the x-axis tick mark labels,
# the same height as the strip
gt = gtable_add_rows(gt, gt$height[min(panels$t)-1], max(panels$b) + 2)

# Get the strip grob
stripGrob = gtable_filter(gt, "strip-t")

# Insert the strip grob into the new row
gt = gtable_add_grob(gt, stripGrob, t = max(panels$b) + 3, l = min(panels$l), r = max(panels$r))

# remove the old strip
gt = gt[-(min(panels$t)-1), ]

grid.newpage()
grid.draw(gt)