Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R ggplot2:如何将自定义主题保存到(高分辨率)PDF_R_Ggplot2_Scatter Plot - Fatal编程技术网

R ggplot2:如何将自定义主题保存到(高分辨率)PDF

R ggplot2:如何将自定义主题保存到(高分辨率)PDF,r,ggplot2,scatter-plot,R,Ggplot2,Scatter Plot,我已经为ggplot2散点图创建了一个自定义主题,但是当我尝试将绘图保存为PDF时,字体会返回默认字体,网格线和面板颜色也会返回默认 问题是:如何将我在RStudio plot viewer中看到的内容准确地转换为高分辨率PDF 图片:下面的第一张图片显示了我想要的(在RStudio中的外观);第二张图片显示了错误布局的PDF 这就是我想要的(RStudio情节) 但这就是我得到的 自定义的ggplot2主题如下所示: windowsFonts("latex" = windowsFont("

我已经为ggplot2散点图创建了一个自定义主题,但是当我尝试将绘图保存为PDF时,字体会返回默认字体,网格线和面板颜色也会返回默认

问题是:如何将我在RStudio plot viewer中看到的内容准确地转换为高分辨率PDF

图片:下面的第一张图片显示了我想要的(在RStudio中的外观);第二张图片显示了错误布局的PDF

这就是我想要的(RStudio情节)

但这就是我得到的

自定义的ggplot2主题如下所示:

windowsFonts("latex" = windowsFont("CMU Serif")) 

mytheme <- theme(text = element_text(family = "latex"), 
             panel.grid.minor = element_blank(), 
             panel.grid.major = element_line(
               colour="grey97", 
               size = (0.01)), 
             panel.background= element_blank(),
             strip.text.x = element_text(size=12),
             strip.background = element_rect(fill="lightgrey",
                                             color = "black",
                                             size = 0.5),
             panel.border = element_rect(color = "black", 
                                         fill = NA, 
                                         size = 0.5))

有什么我可以添加到ggsave代码中,以便它可以保存RStudioplot的准确输出吗?

汤姆:看来我在ggsave之前没有保存plot+主题。这就成功了——非常感谢:-)

但是,现在看来(嵌入)我的字体有问题:

windowsFonts("latex" = windowsFont("CMU Serif"))
当我使用上面相同的代码将绘图保存为PDF时,不会打印任何文本,只打印第一个条带(请参见下图),我得到以下错误:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,: invalid font type

以下是绘图代码,顺便说一句:

plot <- ggplot(ogna, aes(Birthyear, PRES_E)) +
geom_point(aes(fill = SJ_S), 
         shape = 21, 
         color = "black", 
         size = 3) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 3), limits = c(1930, 2000)) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 5), limits = c(-5, 105)) +
facet_grid(. ~ Generation) 

plot汤姆:看来我在保存之前没有保存plot+主题。这就成功了——非常感谢:-)

但是,现在看来(嵌入)我的字体有问题:

windowsFonts("latex" = windowsFont("CMU Serif"))
当我使用上面相同的代码将绘图保存为PDF时,不会打印任何文本,只打印第一个条带(请参见下图),我得到以下错误:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,: invalid font type

以下是绘图代码,顺便说一句:

plot <- ggplot(ogna, aes(Birthyear, PRES_E)) +
geom_point(aes(fill = SJ_S), 
         shape = 21, 
         color = "black", 
         size = 3) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 3), limits = c(1930, 2000)) +
scale_y_continuous(breaks = scales::pretty_breaks(n = 5), limits = c(-5, 105)) +
facet_grid(. ~ Generation) 

plot请包括用于绘图的代码您确定要将绘图保存为
plot请包括用于绘图的代码您确定要将绘图保存为
plot您知道这一点吗?我特别好奇将情节(ggplot2)(及其主题)保存到一个单独的pdf中,每个情节都打印在一个页面上。你知道这一点吗?我特别好奇将情节(ggplot2)(及其主题)保存到一个pdf中,每个情节都打印在一个页面上。