1 year ago

#367896

test-img

Camilo

Edit or undo segment or text for real time plot in R

Say I want to display a web data stream in real time in a plot in R. Is there a way, to just draw and undraw the most recent text box or segment over the existing plot, rather than drawing the entire plot from scratch each time new data arrives, like done here?.

At the core of this question is how to undo, or edit an existing object in a plot (let it be a segment or text box)

Something like this:

plot(0) #Create background plot

#draw first line and text
grid.segments(0,  0, 0.5,0.5, name="A")
grid.text("A", x = unit(0.5, "npc"),y = unit(0.5, "npc"),name="TA")

#draw second line and text, but erase prior element first
  #erase prior element
   grid.remove("A")
   grid.remove("TA")
grid.segments(0.5,  0.5, 0,0.5, name="B")
grid.text("B", x = unit(0.5, "npc"),y = unit(0.5, "npc"),name="TB")

#draw new incoming element
  #erase prior element
   grid.remove("B")
   grid.remove("TB")
grid.segments(0.5,  0.5, 0.5,1, name="C")
grid.text("C", x = unit(0.5, "npc"),y = unit(0.5, "npc"),name="TC")

r

plot

r-grid

0 Answers

Your Answer

Accepted video resources