Adam SO
Adam SO

Reputation: 10001

R interactive plot?

How can a user interactively change one aspect (e.g., orientation or length of a line) on a 2D plot?

Upvotes: 14

Views: 2272

Answers (3)

bill_080
bill_080

Reputation: 4760

The rpanel package has worked for me.

library(rpanel)    

lvm.draw <- function(panel) {    
  x=0:20    
  plot(x, panel$int + (panel$slo*x), ylim=panel$data, ylab="y", main="Adam's Super Duper Interactive Graph", typ="l", lwd=3, col="red")    
  grid()    
  panel    
}    

ylimdat<-c(-50,50)    
panel <- rp.control(title = "Adam's Panel", data=ylimdat, slo=0.5, int=1.0, size=c(300, 160))    
rp.slider(panel, var=slo, from=-5, to=5, action=lvm.draw, title="Slope", pos=c(5, 5, 290, 70), showvalue=TRUE)    
rp.slider(panel, var=int, from=-50, to=50, action=lvm.draw, title="Intercept", pos=c(5, 70, 290, 90), showvalue=TRUE)    

Upvotes: 8

VitoshKa
VitoshKa

Reputation: 8533

latticist and playwith are offering the interactive functionality for R's statistical plots.

For modifying specific details you can save the graph in SVG format and edit it in inkscape.

Upvotes: 11

Greg Snow
Greg Snow

Reputation: 49670

The tkexamp function in the TeachingDemos package helps you to create a graph with controls to change various options in the plot, there are several examples on the help page that can be run to see how it works.

The TkIdentify function in the same package allows you to drag labels (along with lines pointing from points to labels) to a desired position, you could start with the code from that function (all R, nothing compiled) as a basis for your own dynamic plot that would allow dragging a line.

Upvotes: 2

Related Questions