[R] Interactive plot

Greg Snow Greg.Snow at imail.org
Mon Jun 30 18:33:35 CEST 2008


Here is a way that works for me using tkexamp in the TeachingDemos package (which uses tkrplot internally):

calc2 <- function(mat, vary1=0, vary2=0) calc(mat, c(vary1,vary2))

library(TeachingDemos)
tkexamp( calc2(mat, vary2=vary[2]),
        list(vary1=list('slider',from=0,to=4000, resolution=100, init=vary[1])))

# or

tkexamp( calc2(mat),
        list( vary1=list('slider', from=0, to=4000, resolution=100, init=vary[1]),
                vary2=list('slider', from=0, to=4000, resolution=100, init=vary[2])))

If you really want to use tkrplot directly, let me know, but it is a lot more code than above.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
(801) 408-8111



> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Ron Michael
> Sent: Saturday, June 28, 2008 11:00 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Interactive plot
>
> Hi all,
>
> I have created following codes :
>
>
> mat = cbind(c(0.000059710430,0.000023057380),
> c(0.000023057380, 0.00005971089)) set.seed = 1000 vary =
> runif(dim(mat)[1], 2000, 3000) calc = function(mat, vary)
>     {
>      result = vector(length = (length(vary)+1))
>      result[1] = sqrt(t(vary) %*% vary)
>      for (i in 1 : length(vary))
>         {
>          result[(i+1)] = sum(vary)*sum(vary*mat[,i])
>         }
>      barplot(result)
>      return(result)
>     }
>
>
> Now I want to present the plot in some interactive manner. I
> want to put a slider in the plot where user move the slider
> for the 1st element of the vector "vary" and automatically
> this result will be reflected at the plot window. I already
> gone through some examples of "tkrplot" library, however
> unfortunately could not figure out how i can apply them in my problem.
>
> If anyone here explain me how to do that I would be grateful.
>
> Regards,
>
>
> Send instant messages to your online friends
> http://uk.messenger.yahoo.com
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list