Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active May 24, 2018 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/1e5f732aabe240514843d5034d99bfe5 to your computer and use it in GitHub Desktop.
Save whatalnk/1e5f732aabe240514843d5034d99bfe5 to your computer and use it in GitHub Desktop.
[R] cairo_pdf or Cairo::CairoPDF
```{r}
library(ggplot2)
library(Cairo)
```
```{r}
gp <- ggplot(cars, aes(x=speed, y=dist)) +
geom_point()
gp
```
`cairo_pdf`
```{r}
ggsave(filename = "plot-cars-cairo_pdf.pdf", plot=gp, width=8, height=6, device=cairo_pdf, units = "in")
```
`CairoPDF`
```{r}
library(Cairo)
```
```{r}
CairoPDF(file="plot-cars-CairoPDF", width=8, height=6)
gp
dev.off()
```
```{r}
windowsFonts(`IPAexGothic` = windowsFont("IPAexゴシック"))
gp_ja <- ggplot(cars, aes(x=speed, y=dist)) +
geom_point() +
xlab("スピード") + ylab("停止距離") +
theme_bw(base_family = "IPAexGothic")
gp_ja
```
`cairo_pdf`
```{r}
ggsave(filename = "plot-cars-ja-cairo_pdf.pdf", plot=gp_ja, width=8, height=6, device=cairo_pdf, units = "in")
```
`Cairo::CairoPDF`
```{r}
CairoPDF(file="plot-cars-ja-CairoPDF", width=8, height=6)
gp_ja
dev.off()
```
普通の pdf
フォント埋め込みされず,日本語フォントを指定するとエラー
```{r}
ggsave(filename = "plot-cars-pdf.pdf", plot=gp, width=8, height=6, device=pdf, units = "in")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment