gpt4 book ai didi

r - ggplot2:主题集、pdf 导出和 Illustrator 遇到困难

转载 作者:行者123 更新时间:2023-12-02 09:07:28 25 4
gpt4 key购买 nike

我有一个所有主题元素的列表,这些元素存储为在绘图之前调用的主题。但是,我最近发现,当我导出为 pdf 并尝试在 Adob​​e Illustrator 中打开时,出现错误“Acrobat PDF 文件格式有困难”。我还看到 Illustrator 报告说它的“操作数太少”。但是,当我使用标准主题(例如 theme_set(theme_gray()))时,Illustrator 中没有问题。此外,无论主题如何,我在绘制或保存修改后的图形时都没有问题。

也许有人可以建议 a) 存储和唤起大量主题设置的最佳方式,以及 b) 我的 ggplot2 -> pdf -> Illustrator 问题的根源是什么。

这是我当前的主题、我如何唤起它以及示例情节。请注意,某些参数已被注释掉,作为占位符(如果我稍后需要它们)。

textc <- "grey20"
gridc <- "grey20"
backc <- "white"
fontsize <- 12

new_theme <- theme_set(theme_update(
#axis.title = element_text()
axis.title.x = element_text(colour=textc,size=fontsize,angle=0,hjust=.5,vjust=.5,face="plain"),
axis.title.y = element_text(colour=textc,size=fontsize,angle=90,hjust=.5,vjust=.5,face="plain"),

#axis.text = element_text()
axis.text.x = element_text(colour=textc,size=fontsize,angle=0,hjust=.5,vjust=1.5,face="plain"),
axis.text.y = element_text(colour=textc,size=fontsize,angle=0,hjust=1,vjust=0,face="plain"),

axis.ticks = element_line(colour=gridc, size=0.5, linetype="solid"),
axis.ticks.length = unit(.25,'cm'),
axis.ticks.margin = unit(.25,'cm'),

axis.line = element_line(colour=gridc, size=NA, linetype="solid"),
#axis.line.x = element_line()
#axis.line.y = element_line()

legend.background = element_rect(colour=NA,fill=NA,size=NA,linetype="solid"), # removes title and legend
legend.margin = unit(0,"cm"),
legend.key = element_rect(colour=NA,fill=NA,size=NA,linetype="solid"),
legend.key.size = unit(1, 'cm'), # spacing between entries
#legend.key.height = unit(),
legend.key.width = unit(1,'cm'),
legend.text = element_text(colour=textc,size=fontsize,angle=0,hjust=0,vjust=0,face="plain"),
#legend.title.align = 0,#between 0 and 1
legend.title = element_text(colour=textc,size=fontsize,angle=0,hjust=0,vjust=0,face="plain"),
#legend.title.align = 0,# between 0 and 1

#legend.position = "right"
#legend.direction = "horizonal"
#legend.justification = "center"
#legend.box = "horizontal

panel.background = element_rect(colour=NA,fill=NA,size=NA,linetype="solid"),
panel.border = element_rect(colour=NA,fill=NA,size=NA,linetype="solid"),
panel.margin = unit(c(0, 0, 0, 0),'cm'),
#panel.grid = element_line()
panel.grid.major = element_line(colour=gridc, size=.4, linetype="dashed"),
panel.grid.minor = element_line(colour=gridc, size=.4, linetype="dashed"),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
# panel.grid.major.y = element_blank(),

plot.background = element_rect(colour=NA,fill=backc,size=NA,linetype="solid"),
plot.title = element_text(colour=textc,size=16,angle=0,hjust=0,vjust=1,face="plain"),
plot.margin = unit(c(.25, .25, .25, .25),'in') # top, right, bottom, left

#strip.background = element_rect(colour=NA,fill=NA,size=NA,linetype=NA),
#strip.text
#strip.text.x = element_text(colour=textc,size=fontsize,angle=0,hjust=0,vjust=0,face="plain"),
#strip.text.y = element_text(colour=textc,size=fontsize,angle=-90,hjust=0,vjust=0,face="plain")
))

theme_set(theme_gray())
theme_set(new_theme)
options(scipen=9999) # suppress scientific notation


d <- ggplot(mtcars,aes(x=wt,y=mpg))+
stat_binhex()+
scale_fill_gradientn(colours=c("darkorange2","red","black"),name = "Frequency",na.value=NA)
try(ggsave(plot=d,filename=<some file.pdf>,height=4,width=6))

SessionInfo():

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] grid splines stats graphics grDevices utils datasets methods base

other attached packages:
[1] hexbin_1.26.0 lattice_0.20-10 reshape2_1.2.1 Hmisc_3.10-1 survival_2.36-14
[6] plyr_1.7.1 RColorBrewer_1.0-5 ggplot2_0.9.2.1

loaded via a namespace (and not attached):
[1] cluster_1.14.3 colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 gtable_0.1.1
[6] labeling_0.1 MASS_7.3-22 memoise_0.1 munsell_0.4 proto_0.3-9.2
[11] scales_0.2.2 stringr_0.6.1 tools_2.15.2

最佳答案

axis.line = element_line(colour=gridc, size=NA, linetype="solid") 中的

size=NA 导致问题。如果您不想显示该行,请使用 element_blank

这可能不是一个错误,但我建议您在 github 上提交此问题:https://github.com/hadley/ggplot2/issues将来,ggplot2可能能够检查参数的有效性。

关于r - ggplot2:主题集、pdf 导出和 Illustrator 遇到困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13262470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com