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

ggplot轴标签在officer导出docx时被截断的问题求助

问题:ggplot图表插入Word文档时自定义标签被截断

我需要在文档的有限宽度区域中插入ggplot图表,缩放功能对图表、标题、文本等元素均正常生效,但添加自定义标签后,标签会被ggsave自动截断(scaling参数默认设为1)。已尝试调整边距和内边距,但未解决问题。

相关代码

my_doc <- officer::read_docx()

# Dummy data
data <- data.frame(
  day = as.Date("2017-06-14") - 0:364,
  value = runif(365) + seq(-140, 224)^2 / 10000)

p <- ggplot(data, aes(x=day, y=value)) +
  geom_line() + 
  xlab("") + 
  scale_x_date(
    date_labels = "%b %Y") + 
  scale_y_continuous(
    position = "right") + 
  theme(axis.text.x=element_text(angle=30, hjust=1,vjust= 1,
                                 color = 'black'))
p

my_doc <- body_add_gg(my_doc, value = p, width = 2.3, height = 2.8, res = 1200)

my_doc %>% print(target = "doc.docx")

问题效果

生成的图表中X轴的日期标签出现部分截断,标签文字未完全显示即被裁切。

内容的提问来源于stack exchange,提问作者Arkadi w

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 01:13:29