2015-07-09 14 views
5

Mi chiedevo se qualcuno di voi ha riscontrato il seguente problema: Quando tento di esportare un grafico in PDF per mantenere lucidi utilizzando il seguente codice:Esportazione di griglia ggplot2 in PDF errore: 'Errore in grid.Call.graphics ... tipo di carattere non valido'

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 

ottengo il seguente errore:

enter image description here

'errore in grid.Call.graphics ... non valida tipo di font'

L'immagine viene salvata come PDF, MA tutto il testo degli assi NON è stato salvato.

Ho provato a importare la libreria (extrafont) ma ho ottenuto lo stesso errore indipendentemente dal tipo di carattere che uso.

Qualcuno di voi ha riscontrato questo problema prima del &/o ha qualche suggerimento su come risolverlo?

Grazie come sempre.

Edit:

Ecco alcuni dati di esempio per 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 

Ci sono 3 condizioni visive: destro Circle 1 °; Sinistra Circle 1st SIM Cirlce Presentation.

Esistono 5 condizioni audio: 1 Bip centrale; 2 segnali acustici centrali; Left Beep 1st; Right Beep 1st; Nessun segnale acustico.

E ci sono 3 opzioni di rapporto: Sinistra; Destra; SIM.

+0

Potrebbe per favore fare un piccolo esempio riproducibile? – tonytonov

+0

Ciao @tonytonov, ho aggiunto alcuni dati di esempio. – Docconcoct

risposta

2

Il problema è stato apparentemente causato da un override multiplo di axis.title.x (con vjust e size). Ho riformattato il codice e fatto un po 'di pulizia, e ora funziona correttamente.

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

Potrei dover aggiungere altro codice all'esempio. Il mio codice è piuttosto brutto e certamente potrebbe usare la pulizia, ma ho messo in atto lucidi specifici (ho omesso qui) ecc. Che sembrano essere persi in questo approccio. Ci giocherò un po 'di più e riferirò. Grazie. – Docconcoct

+0

Ho iniziato con il tuo esempio e per mantenere tutto ciò che voglio riguardo i lucidi, ecc. Ho semplicemente aggiunto tutti i temi e geom ecc nella prima istanza di RTs.box invece di crearlo e quindi aggiungere altri in un secondo momento. Questo ha risolto bene il problema. Accetterò la tua risposta quando hai identificato la causa principale del problema. – Docconcoct

+0

Grazie ancora @tonytonov. – Docconcoct

Problemi correlati