Skip to content

ggplot object gets updated without formal assignment #5994

@stitam

Description

@stitam

Below is a simple example in which I prepare two scatter plots using the mtcars data set. var contains the name of the variable in mtcars which should be plotted on the y axis. Notice when I change the value of var the plot is automatically updated without any formal assignment. Does this happen on your end as well? Is this normal behaviour? Many thanks.

library(ggplot2)
data(mtcars)
var <- "cyl"
g <- ggplot(mtcars, aes(get(var), mpg)) + geom_point()
g

# change the value of var
var <- "wt"
# look at the original (!) plot
g

Created on 2024-07-11 with reprex v2.1.1

This was prepared in a clean environment, R v4.4.1, ggplot2 v3.5.1

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