相关疑难解决方法(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
查看次数

如何在独立于轴标签的 ggplot2 中指定图形的大小

假设我有一个数据框并想绘制一个图

df <- melt(iris)

p <- ggplot(data = df, aes(x = Species, y = value)) + 
       geom_boxplot() + theme(aspect.ratio = 1)
Run Code Online (Sandbox Code Playgroud)

然后我想使用 ggsave() 来保存这个图的 pdf

ggsave(plot = p, width = 3, height = 3, dpi = 300, filename = "not squished axis.pdf")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

问题是我想指定绘图本身的尺寸但独立于轴标签,以便下面指定的绘图在轴的绝对长度方面将具有相同的大小和尺寸。

q <- ggplot(data = df, aes(x = Species, y = (value)*10000000)) +
       geom_boxplot() + theme(aspect.ratio = 1)

ggsave(plot = q, width = 3, height = 3, dpi = 300, filename = "squished axis.pdf")
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

有没有办法轻松做到这一点?

这是一个在轴长度方面更接近我想要的图的示例:

在此处输入图片说明

唯一的问题是,通过改变纵横比,我最终压扁了 y …

grid r dimensions ggplot2

9
推荐指数
2
解决办法
8万
查看次数

缩小绘图宽度以为ggrepel标签留出更多空间

我想缩小打印区域,以便为ggrepel当前被切断的标签留出更多空间。我似乎再也无法通过偏移标签nudge_x(),并且我不想缩小文本大小。

我正在尝试寻找一种压缩图表的方法,以使所有组都更靠近中心,从而在x轴的极限处留出更多的标签空间。

在此处输入图片说明

具体来说,我正在尝试将此图编织为纵向PDF。我尝试fig.width在块选项中进行控制,但这只是使整个图表变小了。

我想最大化纵向页面上的宽度,但相对于标签区域缩小打印区域。

---
title             : "The title"
shorttitle        : "Title"

author: 
  - name          : "Me"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Address"
    email         : "email"

affiliation:
  - id            : "1"
    institution   : "Company"

authornote: |
  Note here

abstract: |
  Abstract here.


floatsintext      : yes
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : no
mask              : no
draft             : no
note              : …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 knitr ggrepel

5
推荐指数
1
解决办法
114
查看次数

标签 统计

ggplot2 ×3

r ×3

dimensions ×1

facet-wrap ×1

ggrepel ×1

grid ×1

knitr ×1