M1 Mac环境下ggsave指定300dpi保存图片自动转为72dpi的原因咨询
type="cairo" Fixes It) Great catch on the type="cairo" workaround—let’s break down exactly why this issue pops up on your M1 chip Mac:
The Root Cause: Default Graphics Device Behavior
By default, when you use ggsave() on macOS, it relies on the system’s native Quartz graphics device (the backend powering the base R png() function). Quartz is tightly integrated with macOS’s core graphics stack, and it has a long-standing default DPI of 72—this matches the traditional screen resolution standard for macOS.
On M1/M2 Apple Silicon Macs, this Quartz device prioritizes the system-level default DPI over the dpi parameter you pass to ggsave(). That’s why your 300dpi setting gets ignored, and you end up with a 72dpi image every time.
Why type="cairo" Works
Cairo is a cross-platform, standalone graphics rendering library that’s independent of macOS’s native Quartz stack. When you specify type="cairo" in ggsave(), you’re telling R to use this separate engine instead of Quartz.
Unlike Quartz, Cairo doesn’t defer to system-level DPI defaults. It strictly honors the dpi parameter you set, so it generates the 300dpi high-resolution image you expect. This makes it a reliable workaround for Apple Silicon Macs where the native Quartz device overrides your DPI settings.
A quick side note: This behavior is more pronounced on Apple Silicon because the graphics stack architecture differs from Intel-based Macs. On older Intel Macs, the Quartz device sometimes respected custom DPI settings, but the M1/M2’s updated graphics pipeline doubles down on the system default.
内容的提问来源于stack exchange,提问作者zzw0034

