r - Can't resize graph window? Cursor spinning indefinitely? -


i have following:

require(ggplot2)  p <- ggplot()   # don't put aes() here, separately  df <- data.frame(x=x, y=y)    # ggplot requires dataframes p <- p + geom_line(data=df, aes(x=x, y=y))  # plot graphs using ggplots , color segments p <- p + geom_rect(data=peaks,                    aes(xmin=xstart, xmax=xend,                        ymin = -inf, ymax = inf,                        fill = col),                    alpha=0.4)  # open graphical window displaying graph quartz() print(p) message("press return continue") invisible(readlines("stdin", n=1)) 

the last line ensures graphing window doesn't open , shut script terminates. works fine, except can't resize graphing window when shows up. cursor spinning indefinitely.

aside manually specifying window frame in quartz(), there way me resize graphing window?

there's hint here.

instead of using readlines() keep r script waiting, use locator() (for base plots) or grid::grid.locator() (for ggplot2). not keep script running keep plot window active , resizable. on windows, , works me:

library(ggplot2)  x11() #quartz() on osx ggplot(mtcars, aes(mpg, wt)) + geom_line() grid::grid.locator() 

or

x11() #quartz() on osx plot(mtcars$mpg, mtcars$wt) locator() 

the particular difference between locator() , grid::grid.locator() first let select number of points, , second one, can lead having plot closed if miss click. can find alternatives here, or maybe use replicate(10, grid::grid.locator()).

edit

here's modification should fix both problems mentioned in comments.

instead of readlines() or locator(), can make system sleep while graphics device active. since device should changed null device once window closed, can use our condition:

library(ggplot2)  x11() #quartz() on osx ggplot(mtcars, aes(mpg, wt)) + geom_line()  while(dev.cur() != 1) sys.sleep(1) print("still running".) 

i imagine work on os, (os specific) option while(names(dev.cur()) == "windows").


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -