2015-07-09 38 views
5

Zastanawiam się, czy któryś z was napotkał następujący problem: Kiedy próbuję wyeksportować działkę do pliku PDF w celu zachowują folii za pomocą następującego kodu:Eksportowanie siatki ggplot2 do błędu PDF: "Błąd w grid.Call.graphics ... Niepoprawny typ czcionki"

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 

pojawia się następujący błąd:

enter image description here

'błąd w grid.Call.graphics ... nieprawidłowy typ czcionki'

Obraz zapisuje się jako PDF, ale tekst wszystkich osi NIE został zapisany.

Próbowałem już zaimportować bibliotekę (extrafont), ale otrzymałem ten sam błąd niezależnie od używanej czcionki.

Czy ktokolwiek z was doświadczył tego problemu przed &/lub masz jakieś sugestie, jak go rozwiązać?

Dzięki jak zawsze.

Edit:

Oto przykładowe dane dla 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 

Istnieją 3 warunki optyczny: Prawo Koło 1st; Lewy okrąg 1. Prezentacja Cirlce SIM.

Dostępne są 5 warunków audio: 1 Centralny sygnał dźwiękowy; 2 sygnały centralne; Left Beep 1st; Right Beep 1st; Brak sygnału dźwiękowego.

Dostępne są 3 opcje raportów: Lewo; Dobrze; SIM.

+0

Czy możesz zrobić mały, powtarzalny przykład? – tonytonov

+0

Witam @tonytonov, dodałem kilka przykładowych danych. – Docconcoct

Odpowiedz

2

Problem był pozornie spowodowany wielokrotnym zastąpieniem axis.title.x (z vjust i size). Przeformatowałem kod i dokonałem czyszczenia, a teraz działa poprawnie.

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

Być może będę musiał dodać więcej kodu do przykładu. Mój kod jest dość brzydki i na pewno mógłbym użyć czyszczenia, ale miałem na miejscu konkretne folie (tutaj pominięte) itp., Które wydają się być zagubione w tym podejściu. Zrobię z tym trochę więcej i zgłoś się. Dziękuję Ci. – Docconcoct

+0

Zacząłem od twojego przykładu i aby zachować wszystko, co chcę, w odniesieniu do folii itp. Po prostu dodałem wszystkie motywy i geom itp. Do pierwszej instancji RTs.box zamiast tworzyć ją i następnie dodawać później. To ładnie rozwiązało problem. Przyjmuję twoją odpowiedź po zidentyfikowaniu głównej przyczyny problemu. – Docconcoct

+0

Jeszcze raz dziękuję @tonytonov. – Docconcoct