相关疑难解决方法(0)

在ggplot2中设置facet的绝对大小

我正在为报告创建几个刻面图.刻面的数量在2到8之间变化.理想情况下,我希望每个刻面的绝对大小(跨越图表)是相同的(例如4x4厘米),以便更容易比较它们(它看起来也更好) ).

那可能吗?

df1 <- structure(list(group1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,1L, 1L, 1L, 1L, 1L), .Label = c("S1", "S2"), class = "factor"), group = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), value = 1:12), class = "data.frame", row.names = c(NA, -12L), .Names = c("group1", "group", "value"))

df2 <- structure(list(group1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("S1", "S2"), …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 facet-wrap

14
推荐指数
1
解决办法
1288
查看次数

在gtable对象中设置宽度会折叠图; 这曾经工作但它不再存在.

以下代码用于工作但不再适用.有人知道发生了什么事吗?必须对基础gtable代码进行一些更改.

require(cowplot) # for plot_grid()
require(grid) # for unit_max()

# make two plots
plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + 
  geom_point() + facet_grid(. ~ Species) + stat_smooth(method = "lm") +
  background_grid(major = 'y', minor = "none") + 
  panel_border()
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
  geom_point(size=2.5)

g.iris <- ggplotGrob(plot.iris) # convert to gtable
g.mpg <- ggplotGrob(plot.mpg) # convert to gtable

iris.widths <- g.iris$widths[1:3] # extract the first three widths, 
                                  # corresponding to left margin, y …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gtable cowplot

4
推荐指数
1
解决办法
665
查看次数

标签 统计

ggplot2 ×2

r ×2

cowplot ×1

facet-wrap ×1

gtable ×1