title: Creating a trace plot in R
body: <p>I'm fairly new to using R so I'm sure I'm probably making a few rookie mistakes, but I can't seem to figure out how to create a trace plot for this homework question.</p>
  
  <p>Here's the question:</p>
  
  <p>On any given day, Gary is either cheerful (C), so-so (S), or glum (G). If he is cheerful today then he will be C, S, or G tomorrow with respective probabilities 0.5, 0.4, 0.1. If he is so-so today then he will be C, S, or G with probabilities 0.3, 0.4, 0.3. If he is glum today, he will be C, S, or G with probabilities 0.2, 0.3, 0.5. This can be used to make a 3-state Markov Chain with the following transition matrix:</p>
  
  <pre><code>[0.5 0.4 0.1    
   0.3 0.4 0.3 
   0.2 0.3 0.5]
  </code></pre>
  
  <p>Let the chain run for 50 times and create a trace plot for these 50 steps in R. You may write the code yourself or find an appropriate R package to simulate this.</p>
  
  <p>I've made the matrix and <em>I think</em> I've run the chain 50 times, but can't get the traceplot() function to work.</p>
  
  <pre><code>library(coda)
  library(markovchain)
  
  p &lt;- c(0.5, 0.4, 0.1, 0.3, 0.4, 0.3, 0.2, 0.3, 0.5)    
  PP &lt;- matrix(p, 3, 3, byrow = TRUE)
  mc1 &lt;- new("markovchain", transitionMatrix = PP, states = c("C", "S", "G"), name = "Weather Forecast")
  outs &lt;- markovchainSequence(n = 50, markovchain = mc1, t0 = "C")
  my_outs &lt;- mcmc(outs)
  traceplot(my_outs, smooth = FALSE, col = 1:6, type = "1", xlab = "Iterations", ylab = "oxygen", xlim = 50, ylim = 1)
  </code></pre>
  
  <p>This is the error I've been getting and I'm at a loss of what I need to do to get this to work or what other errors I've made before hand.</p>
  
  <pre><code>Error in plot.window(...) : invalid 'xlim' value    
  In addition: Warning messages:
  1: In xy.coords(x, y, xlabel, ylabel, log = log) :
    NAs introduced by coercion
  2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
  </code></pre>
  
  <p>Here's the example trace plot our professor gave us </p>
  
  <p><img src="https://i.stack.imgur.com/E5kxE.png" alt="traceplot"></p>