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
相关产品推荐
相关产品推荐

