8

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

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

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

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 
4

1 回答 1

3

size=NAaxis.line = element_line(colour=gridc, size=NA, linetype="solid")导致问题。element_blank如果您不想显示线条,请使用。

这可能不是bug,但我建议你在github上提出这个问题:https ://github.com/hadley/ggplot2/issues 将来,ggplot2可能有能力检查参数的有效性。

于 2012-11-07T14:26:15.370 回答