2015-07-09 4 views
5

Ich frage mich, wenn einer von Ihnen das folgende Problem aufgetreten ist: Wenn ich versuche, ein Grundstück in PDF zu exportieren, um behalten Folien mit dem folgenden Code:Exportieren von ggplot2 Raster zu PDF-Fehler: 'Fehler in grid.Call.graphics ... ungültige Schriftart'

f <- function(x) { 
    ans <- boxplot.stats(x) 
    data.frame(ymin = ans$conf[1], ymax = ans$conf[2], y = ans$stats[3]) 
} 

RTs.box = ggplot(mean.vis.aud.long, aes(x = Report, y = RTs, fill = Report)) + theme_bw() + facet_grid(Audio~Visual) 
RTs.box + 

geom_boxplot(outlier.shape=1) + geom_hline(yintercept = .333, linetype = 3, alpha = .8) + theme(legend.position = "none") + ylab("Reposponse Times ms") + scale_fill_grey(start=.4) + 
labs(title = expression("Visual Condition")) + theme(plot.title = element_text(size = rel(1)))+ 
theme(panel.background = element_rect(fill = "grey90"), panel.grid.minor = element_blank())+ stat_summary(fun.data = f, geom = "crossbar", 
      colour = NA, fill = "white", width = 0.75, alpha = .9)+ 
geom_boxplot(fill = "transparent", outlier.shape=1)+ 
theme(axis.title.y = element_text(vjust=0.5)) + 
theme(axis.title.x = element_text(vjust=-0.5)) + 
theme(text=element_text(size=30))+ 
theme(axis.title.x=element_text(size=40))+ 
theme(axis.title.y=element_text(size=40))+ 
theme(plot.title = element_text(size = 40, vjust=1))+ #vjust respositions text 
coord_cartesian(ylim = c(0, 3000))+# This allows clipping of plot without dicarding data in analysis 
scale_y_continuous(breaks = (seq(0,3000,by = 500)))+ 
theme(axis.text.y =element_text(size=17, (hjust=-.5)))+ # THIS CHANGES SIZE OF VALUES ON Y-AXIS 
theme(panel.margin = unit(1.2, "lines"))# moves panels further apart 

ich die folgende Fehlermeldung erhalten:

enter image description here

'Fehler in grid.Call.graphics ... ungültige Schriftart'

Das Bild wird als PDF gespeichert, aber der Text der Achsen wurde NICHT gespeichert.

Ich habe versucht, Bibliothek (Extrafont) zu importieren, aber bekomme den gleichen Fehler unabhängig davon, welche Schriftart ich verwende.

Hat jemand von Ihnen dieses Problem vor &/oder haben Sie Vorschläge, wie Sie es lösen können?

Danke wie immer.

Edit:

Hier einige Beispieldaten für mean.vis.long:

Visual    Audio   Report subject_nr RTs 
Right Circle 1st 2 Central Beeps Right 10   717.6936 
Right Circle 1st Left Beep 1st Left 10   540.0408 
Right Circle 1st 1 Central Beep SIM  10   540.0408 
Right Circle 1st No Beep   Right 10   717.6936 
Right Circle 1st Right Beep 1st Left 10   540.0408 
Right Circle 1st Left Beep 1st SIM  10   540.0408 
Left Circle 1st  2 Central Beeps Right 10   717.6936 
Left Circle 1st  Left Beep 1st Left 10   540.0408 
Left Circle 1st  1 Central Beep SIM  10   540.0408 
Left Circle 1st  No Beep   Right 10   717.6936 
Left Circle 1st  Right Beep 1st Left 10   540.0408 
Left Circle 1st  Left Beep 1st SIM  10   540.0408 
Left Circle 1st  2 Central Beeps Right 10   717.6936 
SIM Circle Pres  Left Beep 1st Left 10   540.0408 
SIM Circle Pres  1 Central Beep SIM  10   540.0408 
SIM Circle Pres  No Beep   Right 10   717.6936 
SIM Circle Pres  Right Beep 1st Left 10   540.0408 
SIM Circle Pres  Left Beep 1st SIM  10   540.0408 

Es gibt 3 Sichtbedingungen: Right Kreis 1.; Linker Kreis 1. SIM Cirlce Präsentation.

Es gibt 5 Audio-Bedingungen: 1 Central Beep; 2 zentrale Signaltöne; Left Piep 1 .; Richtiger Piepton 1 .; Kein Piepton.

Und es gibt 3 Bericht Optionen: Links; Recht; SIM.

+0

Könnten Sie bitte ein kleines reproduzierbares Beispiel erstellen? – tonytonov

+0

Hallo @tonytonov, ich habe einige Beispieldaten hinzugefügt. – Docconcoct

Antwort

2

Das Problem wurde scheinbar durch mehrfaches Überschreiben von axis.title.x (mit vjust und size) verursacht. Ich habe den Code neu formatiert und etwas geputzt und jetzt funktioniert es richtig.

RTs.box <- 
    ggplot(mean.vis.aud.long, aes(x = Report, y = RTs, fill = Report)) + 
    geom_boxplot(outlier.shape=1) + 
    geom_hline(yintercept = .333, linetype = 3, alpha = .8) + 
    stat_summary(fun.data = f, geom = "crossbar", 
       colour = NA, fill = "white", width = 0.75, alpha = .9) + 
    facet_grid(Audio~Visual) + 
    scale_fill_grey(start = .4) + 
    scale_y_continuous(breaks = (seq(0,3000,by = 500))) + 
    ylab("Reposponse Times ms") + 
    ggtitle("Visual Condition") 

RTs.box + 
    theme_bw() + 
    theme(legend.position = "none") + 
    theme(plot.title = element_text(size = rel(1))) + 
    theme(panel.background = element_rect(fill = "grey90"), 
     panel.grid.minor = element_blank()) + 
    theme(panel.margin = unit(1.2, "lines")) + 
    theme(text = element_text(size=30)) + 
    theme(axis.title.y = element_text(size=40, vjust=0.5)) + 
    theme(axis.title.x = element_text(size=40, vjust=-0.5)) + 
    theme(plot.title = element_text(size=40, vjust=1)) + 
    theme(axis.text.y = element_text(size=17, hjust=-.5)) 
+0

Ich muss möglicherweise mehr Code zu dem Beispiel hinzufügen. Mein Code ist ziemlich hässlich und könnte sicherlich Reinigung verwenden, aber ich hatte bestimmte Transparenzen (ich habe hier weggelassen) usw., die bei diesem Ansatz verloren scheinen. Ich werde ein bisschen mehr damit spielen und zurück melden. Vielen Dank. – Docconcoct

+0

Ich begann mit Ihrem Beispiel und um alles so zu halten, wie ich es in Bezug auf Transparenzen usw. möchte, fügte ich einfach alle Themes & Geom usw. in die erste Instanz von RTs.box ein, statt sie zu erstellen und später hinzuzufügen. Das hat das Problem gut gelöst. Ich akzeptiere Ihre Antwort, da Sie die Ursache des Problems identifiziert haben. – Docconcoct

+0

Danke nochmal @tonytonov. – Docconcoct

Verwandte Themen