Mastering Development

Can ggplot only plot x and y as isolated vectors?

I know this is too simple of a question but can ggplot (or any plotting function in ggplot2) only plot x and y as isolated vectors (not from a data.frame)?

   x <- rnorm(30)
   y <- rnorm(30)
   d <- data.frame(x, y)

  ggplot(d)+ geom_point(aes(x,y)) # I know this works but this requires `x` & `y` to be from a `data.frame`

 ## But is there a plotting function ggplot2 that would work just like:

 plot(y~x)  # using `x` and `y` directly without a `data.frame`


Leave a Reply

Your email address will not be published. Required fields are marked *