Skip to content

geom_text() does not store current result in plot #6301

Closed
@baderstine

Description

@baderstine

I found what I believe is a problem with geom_text() but perhaps is the intended behavior.

When saving a plot that contains a geom_text() element, I expected the value of the label at the time that the plot object was "saved"/"created" to remain the same regardless of whether the value of the label later changes. However, it appears that the saved plot changes when the label value changes.

Here is the code to reproduce the bug:

library(ggplot2)
dat_iris = iris
v1 = "label a"
p1 = ggplot() + 
  geom_point(data = dat_iris, mapping = aes(x=Sepal.Length, y=Sepal.Width)) + 
  geom_text(aes(x=4, y=4, label = v1))
p1

p1 shows "label a" as expected

v1 = "label b"
p1

p1 shows "label b" rather than "label a" the value of v1 when p1 was created.

This is unexpected because geom_point() behaves differently.

If the data in the data argument to geom_point() changes, p1 displays the original data as it was at the time that p1 was created not the modified data:

> dat_iris[1,'Sepal.Length']
[1] 5.1
> dat_iris[1,'Sepal.Length'] = 10
> dat_iris[1,'Sepal.Length']
[1] 10
> iris[1,'Sepal.Length']
[1] 5.1

p1 

p1 appears exactly the same.

Perhaps this is not a bug, but it is certainly not the behavior that I would have expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions