title: rotate X axis labels 45 degrees on grouped bar plot R
body: <p>How can I rotate the X axis labels 45 degrees on a grouped bar plot in R?</p>
  
  <p>I have tried the solution suggested <a href="https://stackoverflow.com/questions/10286473/rotating-x-axis-labels-in-r-for-barplot">here</a> but got something very messy, the labels seem to have been added multiple times (only showing the axis part to protect data privacy):
  <img src="https://i.stack.imgur.com/a3rsR.png" alt="enter image description here"></p>
  
  <p><a href="https://stackoverflow.com/questions/9981929/how-to-display-all-x-labels-in-r-barplot">This solution</a> (gridBase) was also unsuccessful for me, for some reason I get the following error:</p>
  
  <blockquote>
    <p>"Cannot pop the top-level viewport (grid and graphics output mixed?)"</p>
  </blockquote>
  
  <p>PS.
  Most people seem to recommend <a href="http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f" rel="nofollow noreferrer">this solution</a> in R base but I am stuck with that too because I don't understand what data they are referring to (I need some kind of example data set to understand new command lines...).</p>
  
  <p>Are these solutions not working because my barplot is a grouped barplot? Or should it work nevertheless? Any suggestions are welcome, I have been stuck for quite some time. Thank you.</p>
  
  <p>[edit] On request I am adding the code that I used to generate the picture above (based on one of the text() solutions):</p>
  
  <pre><code>data &lt;- #this is a matrix with 4 columns and 20 rows;
          #colnames and rownames are specified.
          #the barplot data is grouped by rows
  
  lablist &lt;- as.vector(colnames(data))
  
  barplot(data, beside=TRUE, col=c("darkred","red","grey20","grey40"))
  text(1:100, par("usr")[1], labels=lablist, srt=45, pos=1, xpd=TRUE)
  </code></pre>