ggplot2 does not print geom_text() after updating R, RStudio and ggplot2

Working under WIN10-64, I have updated R from 3.5.1 to 3.6.2, RStudio from 1.2.1335 to 1.2.5033 and ggplot2 from 3.0.0 to 3.2.1. Since then, a graphics function which worked flawlessly so far, shows all expected geom_lines, geom_labels and axis labs, but completely lacks all geom_text annotations. These annotations invariably have a structure as shown:

...ggplot()+ geom_line() ...+ # several elements - working correctly´ ´... geom_label()...+ # several elements - working correctly´ ´...geom_text(aes(x=min(xB), y=ymax+0.1*ysp, ´ ´label=("short text elements")),´ ´size=3.0, color=1, hjust="left") +... ´# several annotations - not showing up´

The "short text elements" are string variables or strings concatenated with numeric variables using paste0().

I am unable to find any reason for this change. An attempt to downgrade ggplot2 back to version 3.0.0 was unsuccessful: again, the text annotations did not show up. There is no error message whatsoever. The R-program itself, which produces the necessary data and within which the graphics function is called, is working correctly as usual.

I would be very grateful to receive any possibly helpful hint to solve this problem.
Thanks in advance,

What happens if you try a simple case like the following?

DatFrm <- data.frame(x = 1:5, y = 11:15, Label = LETTERS[1:5])
ggplot(DatFrm, aes(x, y)) + geom_point() + geom_text(aes(label = Label, vjust = -1))

Created on 2020-01-12 by the reprex package (v0.3.0)

Hi, tnx for prompt reply & sample program: it's working perfectly, with both ggplot2 3.0.0 as well as 3.2.1.

So - what could be the problem in my case? A main difference could be, that I cannot use one data frame for all elements - they need fairly different data sources:

  • there are 4 geom_lines with the same x-coordinates, but 4 different y's (and they are printed correctly)
  • there are 4 geom_labels with individual (x,y)-coordinates, printed correctly, too
  • only 9 geom_texts with quite special (x,y)-coordinates (partly tied to max/min values of some of the lines etc) have problems

But all that isn't so different from your example. And it did work so far. I'm at a loss, really...

It seems you have a complicated data structure that would not be convenient to post on the forum.Without seeing the data, my suggestion is to work the problem backwards and start with a plot showing only the text elements that are currently missing. Inspect the x and y values carefully. Are they really numeric or possibly factors? Then add one geom_line at a time and slowly build up the plot. I hope that will highlight just where your structure for the plot has an inconsistency. If you find that point and still cannot see the problem, you may be able to at least post here with a minimal data set that demonstrates just where the problem lies.

1 Like

Hi, tnx again. And your reply definitely was helpful: I took your sample program, plugged one of my geom_text-blocks into it with suitable adaptations of coordinates etc., and removed one after the other attributes.

When ´color=1´ was removed, everthing looked normal... and as soon as I replaced ´color=1´ by ´color="black"´, the problem was cured. Thus, no color initiates the default, i.e. black. And the new ggplot2 apparently doesn't accept text coloring by numbers - which the old version actually did.

The same happens if I add color to the points in your program; not, however in case of the labels - they follow different rules, just try it out: with color="black" they get kind of greyish, for color=1 blue, and omitting color at all makes them black. A bit inconsistent, if you ask me...

I thank you very much for your support - it definitely was a success for me to get rid of this rather strange problem. Have a nice time!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.