我有一个所有主题元素的列表,这些元素存储为在绘制之前引起的主题。但是,我最近发现,当导出为pdf并尝试在Adobe 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

最佳答案

size=NA中的axis.line = element_line(colour=gridc, size=NA, linetype="solid")导致此问题。
如果不想显示该行,请使用element_blank

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

10-08 15:10