[R-gui] embedding R graphics in Tk widgets
Sebastian P. Luque
spluque at gmail.com
Thu Jul 3 19:32:19 CEST 2008
On Thu, 3 Jul 2008 10:19:40 -0700,
"Michael Lawrence" <mflawren at fhcrc.org> wrote:
[...]
> Just pack the ggraphics widget to expand (= TRUE).
I tried that, but the graph still doesn't seem to be resized along with
the changing size of the window (see below).
>> How about the initial plot not being produced?
> I don't see enough of your code to tell why - where you are you
> plotting the data?
It's the vignette's density example. Here it is:
---<---------------cut here---------------start-------------->---
availDists <- c(Normal="rnorm", Exponential="rexp")
availKernels <- c("gaussian", "epanechnikov", "rectangular",
"triangular", "biweight", "cosine", "optcosine")
updatePlot <- function(h, ...) {
x <- do.call(availDists[svalue(distribution)], list(svalue(sampleSize)))
plot(density(x, adjust=svalue(bandwidthAdjust),
kernel=svalue(kernel)), main="Density plot")
rug(x)
}
distribution <- gradio(names(availDists), horizontal=FALSE, handler=updatePlot)
kernel <- gdroplist(availKernels, handler=updatePlot)
bandwidthAdjust <- gslider(from=0,to=2,by=.01, value=1, handler=updatePlot)
sampleSize <- gradio(c(50,100,200, 300), handler=updatePlot)
window <- gwindow("gWidgetsDensity")
bigGroup <- ggroup(container=window)
vGroup <- ggroup(horizontal=FALSE, container=bigGroup)
hGroup <- ggroup(horizontal=FALSE, container=bigGroup)
## Now to add a graphics device. [Again, if using \RFunc{gWidgetsrJava}
## this wouldn't place the device inside the \RCode{BigGroup} container.]
add(hGroup, ggraphics(), expand=TRUE)
tmp <- gframe("Distribution", container=vGroup)
add(tmp, distribution)
tmp <- gframe("Sample size", container=vGroup)
add(tmp, sampleSize)
tmp <- gframe("Kernel", container=vGroup)
add(tmp, kernel)
tmp <- gframe("Bandwidth adjust", container=hGroup)
add(tmp, bandwidthAdjust, expand=TRUE)
---<---------------cut here---------------end---------------->---
--
Seb
More information about the R-SIG-GUI
mailing list