-
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
Incompatibility with ggplotGrob() #22
Comments
You'll probably need
|
I encountered a similar issue (text disappearing while the rest of the plot shows) in the shiny app. Would love to see if there's a solution to this issue to get inspired (I used ggplotGrob for other graphs earlier today, which may or may not be the cause of my shiny app plot issue). For the specific issue of using ggplotGrob with showtext as mentioned by @nalsalam, I updated R to 3.5.2 and can still replicate the issue. The solution suggested by @tungmilan did not work, unfortunately. ===== |
I'd like to use non-standard fonts in a ggplot but I also want to manipulate some widths so that several plots align vertically. Unfortunately after converting to a plot Grob all font information is lost. This may be related to issue #1.
R 3.5.1, ggplot2 3.0.0, showtext 0.5-1
library(ggplot2)
data <- data.frame(x = c(rnorm(1000)))
before <- ggplot(data = data) +
geom_histogram(aes(x), fill = "steelblue", color = "white", bins = 30) +
labs(title = "Histogram of Normal Random Numbers",
subtitle = "Histogram of Normal Random Numbers",
y = "Frequency",
x = "Normal Random Variable")
ggsave("before.pdf", plot = before)
(I have a need to modify widths of plots, so I create a plot Grob. Not showing that here.)
before2 <- ggplotGrob(before)
ggsave("before2.pdf", plot = before2, width = 7, height = 7)
But I want to use non-standard fonts, so...
library(showtext)
font_add_google("Schoolbell", "bell")
after <- before +
theme(text = element_text(family = "bell")) +
annotate("text", x = 2, y = 70, label = "N = 1000", size = 10, family = "bell")
as expected, the pdf has the non-standard font
showtext_auto()
ggsave("after.pdf", plot = after, width = 7, height = 7)
showtext_auto(F)
Oh, no! All text disappears
showtext_auto()
after2 <- ggplotGrob(after)
ggsave("after2.pdf", plot = after2, width = 7, height = 7)
Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
invalid font type
In addition: There were 50 or more warnings (use warnings() to see the first 50)
showtext_auto(F)
No errors or warnings but non-standard font is replaced with a serif font
showtext_auto()
ggsave("after2.svg", plot = after2, width = 7, height = 7)
The text was updated successfully, but these errors were encountered: