-
-
Save jdmar3/c0c868948fa77d582188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(Cairo) # MAGIC PACKAGE | |
fake.data <- data.frame(x = rnorm(100), y = rnorm(100), z = rbinom(100, 1, 0.5)) | |
p <- ggplot(fake.data, aes(x=x, y=y)) + | |
geom_line() + | |
labs(x="Science", y="More science", title="Here's a title") + | |
facet_wrap(~ z) + | |
theme_bw() + | |
# Add whatever fonts you want to any element_text() things in theme() | |
theme(title=element_text(family="Source Sans Pro Semibold"), | |
axis.title=element_text(family="Source Sans Pro Light"), | |
strip.text=element_text(family="Source Sans Pro Light")) | |
p | |
# device=cairo_pdf is the magic part. That's how the fonts get embedded. | |
ggsave(p, filename="~/Desktop/blah.pdf", | |
width=5, height=3.5, units="in", device=cairo_pdf) | |
ggsave(p, filename="~/Desktop/blah.png", | |
width=5, height=3.5, units="in") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment