You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R技术问题:Quarto中ggcorrplot的fig.width参数在HTML输出中失效

问题原因与解决办法

原因

  • ggcorrplot生成的相关系数矩阵图默认设置了aspect.ratio = 1,强制图表保持正方形宽高比,这会直接覆盖Quarto代码块中fig.width的设置。
  • 普通ggplot绘图没有强制固定宽高比,因此能正常响应fig.width参数。

解决办法

取消ggcorrplot的固定宽高比限制即可让fig.width生效,以下是两种常用方式:

方式1:修改theme参数

在ggcorrplot对象后添加theme(aspect.ratio = NULL):

```{r, fig.width = 20}
# fig.width正常生效
ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess", se = FALSE)

# 修改后fig.width生效
airquality %>%
  cor(use = "pair") %>%
  ggcorrplot() +
  theme(aspect.ratio = NULL)
#### 方式2:使用coord_fixed取消固定比例
通过`coord_fixed(ratio = NULL)`解除宽高比锁定:
```r
```{r, fig.width = 20}
airquality %>%
  cor(use = "pair") %>%
  ggcorrplot() +
  coord_fixed(ratio = NULL)
内容的提问来源于stack exchange,提问作者Pawel Kul
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 10:03:15