3

I don't know if you have seen some unwanted bold-face font like picture below:

enter image description here

As you see the third line is bold-faced, while the others are not. This happens to me when I try to use ggplot() with lapply() or specially mclapply(), to make the same chart template based on different data, and put all the results as different charts in a single PDF file.

One solution is to avoid using lapply(x, f) when f() is a function that returns a ggplot() plot, but I have to do so for combining charts (i.e. as input for grid.arrange()) in some situation.

Sorry not able to provide you reproducible example, I tried really hard but was not successful because the size of code and data is too big with several nested functions and when I reduced complexity to make a reproducible example, the problem did not happen.

I asked the question because I guessed maybe someone has faced the same experience and know how to solve it.

Ali
  • 9,440
  • 12
  • 62
  • 92
  • [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Arun Jun 09 '13 at 13:22
  • He's right. I suspect I know what is causing this, but try again with the reproducible example. If nothing else, creating a simple example often helps you find the problem yourself... – SlowLearner Jun 09 '13 at 17:51
  • I tried hard again, with small low-complexity programs (as reproducible example) the error does not happen. So I hope somebody has already faced the problem and know how to solve it, even without reproducible example – Ali Jun 12 '13 at 07:21
  • Without data and a reproducible example, I can't be sure of the problem, but I have seen stuff like this. It often has to do with the resolution of the plotting device. I would first try saving the plot as a PDF to see if the issue is related to anti-aliasing, and then I would try significantly increasing the resolution of the plotting device. Often, either of these approaches will produce a more accurate visual for me, and a lot of the artifacts I am seeing on the screen just disappear. This may not be your problem, but perhaps it is a place to start. – Dinre Jun 12 '13 at 12:09
  • @Dinre Thanks but the output is PDF file, that resolution is not a matter. – Ali Jun 12 '13 at 12:38

2 Answers2

2

My intuition is that it's not actually being printed in bold, but rather double-printed for some reason, which then looks bold. This would explain why it doesn't come up with a simpler example. Especially given your mention of nested functions and probably other complicated structures where it's easy to get an off-by-one or similar error, I would try doing something where you can see exactly what's being plotted -- perhaps by examining the length() of the return value from apply().

Changing the order of elements of the vector, so that the order of the elements in the key is different, may also help. If you consistently get the bold-face on the last element, that also tells you a little bit more about where something is going wrong.

As @Dinre also mentioned, it could also be related to your plotting device. You can try out changing your plotting device. I have my doubts about this though, seeing as it's not a consistent problem. You could also try changing the position of the key, which depending on your plotting device and settings, may move you in or out of a compression block, thus changing which artifacts crop up.

Livius
  • 3,240
  • 1
  • 17
  • 28
1

Reproducible example and a solution may be as follows:

library(ggplot2)

d <- data.frame(x=1:10, y=1:10)
ggplot(data = d, aes(x=x, y=y)) +
    geom_point() +
    geom_text(aes(3,7,label = 'some text 10 times')) +
    geom_text(data = data.frame(x=1,y=1), 
              aes(7,3, label = 'some text one time'))

When we try to add a label by geom_text() manually inserting x and y do not shorten the data. Then same label happen to be printed as many times as the number of rows our data has. Data length may be forced to 1 by replacing data within geom_text().

plot

cure
  • 425
  • 2
  • 12