-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using showtext leads to smaller font size in ggplot2 #51
Comments
You may need to set |
Passing the dpi of the current chunk works. Although not very user friendly as I'm using
|
I'm experiencing the same problem. I just entered to the repo to report the same issue. My code good library(ggplot2)
library(ggstatsplot)
library(palmerpenguins)
penguins <- tidyr::drop_na(penguins)
plt <- ggbetweenstats(
data = penguins,
x = species,
y = bill_length_mm,
title = "Distribution of bill length across penguins species",
xlab = "Penguins Species",
ylab = "Bill Length"
)
ggsave("plot_good.png", plt, width = 8, height = 8) bad library(ggplot2)
library(ggstatsplot)
library(palmerpenguins)
library(showtext)
showtext_auto()
penguins <- tidyr::drop_na(penguins)
plt <- ggbetweenstats(
data = penguins,
x = species,
y = bill_length_mm,
title = "Distribution of bill length across penguins species",
xlab = "Penguins Species",
ylab = "Bill Length"
)
ggsave("plot_bad.png", plt, width = 8, height = 8) |
@ThierryO @tomicapretto When using On the other hand, if you use |
Thanks so much for the answer @yixuan! |
I don't know whether the end user will use my code (custom ggplot2 theme) in a plain R script or an Rmd. What would you recommend to keep it user friendly? |
Hi, I made a reprex just for completeness as this had been confusing me for quite some time. Thanks for your answer @yixuan! library(cowplot)
library(ggplot2)
library(pdftools)
library(png)
library(showtext)
p <- ggplot(data = PlantGrowth,
aes(y = weight, x = group)) +
geom_point() +
labs(title = "This is the title",
subtitle = "Here is also a subtitle",
caption = "And here is a caption")
# Standard - not involving {showtext} -------------------------------------
ggsave("p1.png", p)
#> Saving 7 x 5 in image
ggsave("p1.pdf", p)
#> Saving 7 x 5 in image
png1 <- readPNG("p1.png")
pdf1 <- pdf_render_page("p1.pdf", page = 1, dpi = 300)
plot_grid(ggdraw() + draw_image(png1) + draw_label("png"),
ggdraw() + draw_image(pdf1) + draw_label("pdf")) # showtext::showtext_auto() -----------------------------------------------
showtext::showtext_auto()
ggsave("p2.png", p)
#> Saving 7 x 5 in image
ggsave("p2.pdf", p)
#> Saving 7 x 5 in image
png2 <- readPNG("p2.png")
pdf2 <- pdf_render_page("p2.pdf", page = 1, dpi = 300)
plot_grid(ggdraw() + draw_image(png2) + draw_label("png"),
ggdraw() + draw_image(pdf2) + draw_label("pdf")) # showtext::showtext_auto() & showtext_opts(dpi = 300) --------------------
showtext::showtext_auto()
showtext_opts(dpi = 300)
ggsave("p3.png", p)
#> Saving 7 x 5 in image
ggsave("p3.pdf", p)
#> Saving 7 x 5 in image
png3 <- readPNG("p3.png")
pdf3 <- pdf_render_page("p3.pdf", page = 1, dpi = 300)
plot_grid(ggdraw() + draw_image(png3) + draw_label("png"),
ggdraw() + draw_image(pdf3) + draw_label("pdf")) Created on 2022-07-29 by the reprex package (v2.0.1) |
Reproducible example.
The text was updated successfully, but these errors were encountered: