0

I have data to be shown on a barplot, with groups varying between 1 and 50. However, not all labels appear on X axis. I really don't want all of it, but from 5 to 5. Can I choose this? R is naming bars on a random order (sometimes from 4 to 4, sometimes 3 to 3).

  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including the code you have tried and a snippet of your data or some fake data. – stefan Jan 31 '23 at 20:39

1 Answers1

3

Here is a simplified example of four values. First, you need to create a vector of X labels and assign those values to missing that you wont to show. Here I want to just show the first and third labels on the X axis:

data <- c(5, 7, 3, 9)
labels <- c(1,NA, 3, NA)

then plot the data using the barplot function and choose labels using names.arg option:

barplot(data, xticks = 1:4, names.arg = labels)

enter image description here

S-SHAAF
  • 1,863
  • 2
  • 5
  • 14