1

I am trying to export a simple barplot using ggplot2. Everything works fine, but when the plot is printed it states the following error:

In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), ... : Zeichensatzfamilie in der Windows Zeichensatzdatenbank nicht gefunden

In english it would say:

In grid.Call(L_text, as.graphicsAnnot(x$label), ... : font family not found in Windows font database

When I then try to export the file as pdf using the export button on top of the plot it never finishes saving the plot and I have to close Rstudio with the taskmanager.

I already read I should install the extrafont package, import and load the fonts, which I also did. This is the code I used:

    library(ggplot2)
library(extrafont)
font_import()
y
loadfonts()

Data <- Liposarcoma.ARSA_2 #txt. file with my data
newData <- Data[-c(1,2),] #delete Header


errors <- as.numeric(newData$V10)


samplev <- data.frame(samples=(newData$V3), Target=(as.numeric(newData$V8)))
samplev         #create dataframe for Target/ref


dodge <- position_dodge(width = 0.9)
limits <- aes(ymax = samplev$Target + errors,
              ymin = samplev$Target - errors)
p <- ggplot(data = samplev, aes(x = samples, y = Target))

p + geom_bar(stat = "identity", position = dodge, fill="darkgrey") +
  geom_errorbar(limits, position = dodge, width = 0.25) +
  theme(axis.text.x=element_text(samplev$samples), axis.ticks.x=element_blank(),
        axis.title.x=element_blank(), axis.text=element_text(size=12, colour="black"),
        plot.title=element_text(size=18, face="bold")
        ) +
        ylab("Target/Reference") +
        ggtitle("ARSA: Liposarcoma cell lines") +
        geom_text(data=samplev, aes(x=samples, y=Target+0.15, label=Target, vjust=0))

Thank you in advance :)

9
  • Do you get the same error if you run this without using RStudio? Commented Jan 23, 2016 at 16:31
  • we can't reproduce your error, we don't have access to your dataset. you don't seem to ask for a different font in your plot Commented Jan 23, 2016 at 16:38
  • There is a function named pdfFonts. It might be used to change the default fonts for that graphics device, although (not being an RStudio user yet) I suppose that RStudio might have its own mechanism for controlling graphics devices? Commented Jan 23, 2016 at 16:53
  • Have you tried using the pdf() device or ggsave() instead of the RStudio button? Or setting a font that you know you have? Commented Jan 23, 2016 at 17:13
  • @Dason : Yes, I get the same error without using RStudio Commented Jan 24, 2016 at 12:18

1 Answer 1

2

I solved the issue. The problem was that I thought I would specify my x-labels by using:

axis.text.x=element_text(samplev$samples)

But the first element in element_text implements the fonts, not data! That is why it could not find the font, because the data in samplev$samples is not a font name. The code looks now like this and works perfectly fine:

pdf(file = "Liposarcoma ARSA.pdf")
p <- ggplot(data = samplev, aes(x = samples, y = Target))

p + geom_bar(stat = "identity", position = dodge, fill="#3399FF") +
  geom_errorbar(limits, position = dodge, width = 0.25) +
  theme(axis.text.x=element_text(angle = 45, hjust=1), axis.ticks.x=element_blank(),
        axis.text.y=element_text(size = 12), axis.title.y = element_text(size=15),
        axis.title.x=element_blank(), axis.text=element_text(size=12, colour="black"),
        plot.title=element_text(size=18, face="bold")
        ) +
        ylab("Target/Reference") +
        ggtitle("ARSA: Liposarcoma cell lines") +
        geom_text(data=samplev, aes(x=samples, y=Target+0.1, label=Target, vjust=0))
dev.off()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.