Dynamic title and sliders using the management pack in Rstudio

Using the management pack in Rstudio, I am trying to create a scatter chart in which I can select one of several data frames using the collector, and then using the sliders I control the columns that I would like to build for each axis. For example, using these two datasets: mtcars and iris.

library(manipulate)  
manipulate(  
 plot(dataset[, xaxis] ~ dataset[, yaxis], 
   dataset, 
   xlab = colnames(dataset)[xaxis],
   ylab = colnames(dataset)[yaxis], 
   main = title),
   xaxis = slider(1, 10), 
   yaxis = slider(1, 10), 
   dataset = picker("mtcars" = mtcars, "iris" = iris),
   title = picker("mtcars", "iris")
   )    

This works fine, however I am struggling with two questions:

  • How to dynamically change the chart title based on the selected data set (mtcars or iris) instead of manually using another selection tool, as in the example above. I cannot get the name of the selected data frame and pass it as a character header.

  • , hardcoding 1 10. , mtcars 11 5. , . , , , , ( ) (). , :

    xaxis = (1, as.numeric(dim ( ) [2]))

+4
1

, , Learning RStudio for R Statistical Computing, . . . , :

library(manipulate)
scatterplot <- function(dataset){
  vars <- as.list(names(dataset))
  name <- sys.call()[[2]]
manipulate(
  plot(dataset[, xaxis] ~ dataset[, yaxis], 
       xlab = colnames(dataset)[xaxis],
       ylab = colnames(dataset)[yaxis], 
       main = as.character(name)),   
  xaxis = slider(1, as.numeric(dim(dataset)[2]), initial = 1), 
  yaxis = slider(1, as.numeric(dim(dataset)[2]), initial = 2)  
  )
}
scatterplot(mtcars)
+2

All Articles