qgraph version 1.1.0 and how to simply make a GUI using ‘rpanel’
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Last week I have updated the ‘qgraph‘ package to version 1.1.0, available on CRAN now. Besides some internal changes (especially the self-loops have been substantially improved) the most important change is the addition of a GUI interface, which can be called using the argument gui=TRUE. For example:
data(big5) data(big5groups) qgraph(cor(big5),groups=big5groups,gui=TRUE)
Will open a plotting window and the GUI that allows the user to set several parameters before plotting:
There is also a simplified version of this GUI for regular graphs (not correlation matrices).
What I particularly like about this GUI is that it took me only one day to implement. Making a GUI for qgraph has been on my to do list for a long time, but I never really got to learning how one of the packages that allow this work. When I found out about the ‘rpanel‘ package (which is build on ‘tcltk’) I was pleasantly amazed with how simple and intuitive it was to use.
In short, the way ‘rpanel’ works is by making a ‘panel’ using ‘rp.control()’ which is basically a list and also opens an empty GUI frame. We can use functions such as ‘rp.checkbox’ and ‘rp.slider’ to add elements to the GUI. Using these elements then does two things: an element of the list is changed (e.g., the element ‘xlim’), and a function is called on the list. This way, we can easily make an appropriate GUI element for each argument we need in a plotting function and make buttons that plot, save to PDF, etcetera.
To illustrate this I wrote a small function with comments that uses ‘plot.default’ to plot a scatter plot, and adds a small GUI frame allowing a user to zoom into the scatter plot. The codes can be downloaded here. A small example:
x <- rnorm(100) y <- x + rnorm(100) ScatterZoom(x,y)
More information on 'rpanel' can be found in its Journal of Statistical Software article.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.