Reputation: 57
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).
Upvotes: 0
Views: 97
Reputation: 2140
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)
Upvotes: 3