title: Create a function or for-loop to generate tally marks with base R graphics
body: <p>I'm working on a Shiny App that simply generates tally marks.  I have a long script that does a serviceable job, but I'd like to make it more mathematically succinct so that I can eventually use simple inputs for the app.  Right now, the script is as follows:</p>
  
  <pre><code># create dataframe
  y=c(rep(c(10, 9), 8))
  x = rep(seq(from = 0, to = 3.5, by = 0.5), each=2) 
  d = data.frame(x, y)
  
  # Draw empty plot
  plot(x=NULL, y=NULL, xlim = c(0, 4), ylim = c(0,10), axes = FALSE, xlab= " ", ylab = " ")
  
  # Begin tallies
  segments(d$x[1], d$y[1], d$x[2], d$y[2])
  segments(d$x[3], d$y[3], d$x[4], d$y[4])
  segments(d$x[5], d$y[5], d$x[6], d$y[6])
  segments(d$x[7], d$y[7], d$x[8], d$y[8])
  # diagonal 1
  segments(d$x[1], d$y[1], d$x[8], d$y[8])
  
  # next tally group
  segments(d$x[9], d$y[9], d$x[10], d$y[10])
  segments(d$x[11], d$y[11], d$x[12], d$y[12])
  segments(d$x[13], d$y[13], d$x[14], d$y[14])
  segments(d$x[15], d$y[15], d$x[16], d$y[16])
  # diagonal 2
  segments(d$x[9], d$y[9], d$x[16], d$y[16])
  
  # Row 2 - revalue dataframe to call upon new y values (this is a clunky step 
  I'd like to eliminate as well)
  y=c(rep(c(8, 7), 8))
  x = rep(seq(from = 0, to = 3.5, by = 0.5), each=2) 
  d = data.frame(x, y)
  
  segments(d$x[1], d$y[1], d$x[2], d$y[2])
  segments(d$x[3], d$y[3], d$x[4], d$y[4])
  segments(d$x[5], d$y[5], d$x[6], d$y[6])
  segments(d$x[7], d$y[7], d$x[8], d$y[8])
  # diagonal 1
  segments(d$x[1], d$y[1], d$x[8], d$y[8])
  </code></pre>
  
  <p>... and so on, for a total of 5 rows.  That generates this plot:
  <a href="https://i.stack.imgur.com/lrBL6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lrBL6.png" alt="enter image description here"></a></p>
  
  <p>I'd like to automate the generation of the plot with a for-loop or a function, but my only (admittedly mathematically flawed) attempt generates connected line segments, and I've no idea how to begin automating the crosshatches:</p>
  
  <pre><code>plot(x=NULL, y=NULL, xlim = c(0, 4), ylim = c(0,10), axes = FALSE, xlab= " ", ylab = " ")
  
  for( i in 1:16 ) {
    segments(d$x[i], d$y[i], d$x[i+1], d$y[i+1])
  }
  </code></pre>
  
  <p>I'm sure I'm just organizing the problem wrong.  This is a frivolous coding project, but any suggestions would be much appreciated!</p>