Attempts to save a plot to PDF and optionally PNG. If saving fails due to the "Viewport has zero dimension(s)" error (often caused by too many legend entries), the legend is removed and the plot is saved again.
Usage
save_plot_with_fallback(
plot,
pdf_file,
png_file = NULL,
width = NULL,
height = NULL,
dpi = 300
)