use of Sys.Sleep

Asked

Viewed 99 times

3

I can’t make a point-to-point graph, the R plot the graph then stays in the count of the Sys.sleep, someone help me?

  n=1
  Cn=6.45
  x<-3
  t<- seq(1,20)
  for (i in 1:21) {
  flux  = round(Cn*sin(n*pi*x / 5)*exp(-(pi^2*n^2/25)*t), digits = 2)
  flux
  plot(flux, type = "o", col = "red4")
  Sys.sleep(.25)
  }

How can I increase the chart size?

1 answer

1

Point-to-point graph would be a graph like an animation? If so, the code below solves your problem:

# criacao as variaveis e calculo do flux

n  <- 1
Cn <- 6.45
x  <- 3
t  <- seq(1, 20)
flux  <- round(Cn*sin(n*pi*x / 5)*exp(-(pi^2*n^2/25)*t), digits=2)

# cria um grafico vazio com as dimensoes
plot(flux ~ t, type="n") 

for (i in 1:length(t)) {
  points(flux[i] ~ t[i], type="o", col="red4")
  Sys.sleep(.25)
}

The problem with the original code was using the command plot(flux, type = "o", col = "red4"). It was run 21 times, always creating a full chart with all 20 points. When using the command points, I can add the dots on the chart one by one without deleting the previous ones.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.