Why does plot show up in global environment but not as an actual plot?

Hi all, I'm a little new to R studio.

When I do a code with ggplot to make a line graph it works beautifully and presents a line graph in the plot area. however, if I try to name the plot to source it later with "<-" followed by the same line of code then in shows up in the global environment instead of graphing it.

Thats standard R behaviour so if you want to assign a result to a name and also then display you have two options.
just repeat the name of the object as your next line of code. or wrap the code which does the assignment in a pair of brackets.

# first way
p1 <- ggplot(data=iris,aes(x=Petal.Length,y=Petal.Width)) + geom_point()

# second way
(p2 <- ggplot(data=iris,aes(x=Sepal.Length,y=Sepal.Width)) + geom_point())

simple fix! thank you so much for your response and patience.

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