If I run the following code, everything works as expected and the plot shows on the right panel in RStudio:
plot(x=iris$Sepal.Width, y=iris$Sepal.Length)
However, if instead I call the plot from my own custom function, it no longer shows the plot. Why?
a <- function() {
plot(x=iris$Sepal.Width, y=iris$Sepal.Length)
}
a
EDIT: As per the comments, I forgot to call a
as a()
. However, I have another scenario in which, once again, the plot is not being created, and I do not know why, this time with ggplot:
a <- function() {
ggplot(iris, aes(x=Sepal.Width, y=Sepal.Length)) +
geom_point()
return(1)
}
b <- a()
If I return a value from the function, the plot is not created.