When long text is placed along y-axis in ggplot
and cairo_pdf
is called without width
and height
, it uses width = 7, height = 7
parameters, so that wide plots can't fit the output PDF.
Is it possible to let cairo_pdf
decide the size of the PDF for readers to see the entire plot in the produced PDF?
Here one can find solution via ggsave
, but it doesn't fit this case because ggsave
has problems with non-Latin characters in PDF output.
A code example:
cairo_pdf
: Well-behaving PDF. The plot doesn't fit the PDF.
cairo_pdf("out_cairo.pdf")
df <- data.frame(x = c("Несмотря на то, что доктора лечили его, пускали кровь и давали пить лекарства, он всё-таки выздоровел.", "B"), y = c(15, 20))
ggplot(df, aes(x = x, y = y)) +
stat_summary(fun.y = "mean", geom = "bar") +
coord_flip()
dev.off()
pdf
: Text is overlapping.
pdf("out_pdf.pdf")
df <- data.frame(x = c("Несмотря на то, что доктора лечили его, пускали кровь и давали пить лекарства, он всё-таки выздоровел.", "B"), y = c(15, 20))
ggplot(df, aes(x = x, y = y)) +
stat_summary(fun.y = "mean", geom = "bar") +
coord_flip()
dev.off()