1

Sorry to bother you with what is for sure a very simple mistake, but I still cannot figure it out by myself:

library(ggplot2)

X = rep(c(1:6),3)
Y = rep(c(1:6),3)
group = rep(c(1:3), each = 6)

data = data.frame(X = X, Y = Y, group = group)

ggplot(data, aes(x = X, y = Y, group = group)) + geom_point() 

I do not get any output from this when I run as a script -- no figure is created. What am I doing wrong here?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
GeroK
  • 23
  • 3
  • I am getting an output of the above command. Not sure what is your question. Are you asking you are not getting expect output or no output at all? – Prradep Sep 04 '17 at 10:33
  • 1
    Possible scenarios that come to mind: 1 - you're running this within a function / sourcing this from a script (see [here](https://stackoverflow.com/questions/26643852/ggplot-plots-in-scripts-do-not-display-in-rstudio)); 2 - you've called an external graphics device at some point & hasn't closed it yet (see [here](https://support.rstudio.com/hc/en-us/community/posts/200671647-ggplot2-plots-not-appearing-in-plots-window)). Otherwise there's no issue with your code. – Z.Lin Sep 04 '17 at 11:04
  • @Z.Lin: Thank you! I was sourcing this from a script, the linked topic solved to problem. – GeroK Sep 04 '17 at 12:10

1 Answers1

1

Try print the plot if you are calling it from another function or in Shiny:

myplot <- ggplot(data, aes(x = X, y = Y, group = group)) + geom_point() 

print(myplot)
micstr
  • 5,080
  • 8
  • 48
  • 76