Keith Keith - 2 months ago 5
R Question

Don't show all names on r barplot

Well since I'm new here I can't post the image that would make this a whole lot easier.

Essentially, I have 45 pairs of bars in a barplot. Each group of 5 pairs belongs to a different city. What I want to do is only show one name for each group of 5 and not show any repeats.

The code I have so far is:

barplot(matrix(c(sixth_shop, thirteenth_shop), nrow=2, ncol=45, byrow=T),
beside=T, legend.text=c('6th Shoppers', '13th Shoppers'), ylim = c(0, 11000),
col = c('light green', 'navy'), ylab = 'Number of Shoppers', main = 'Total Shoppers',
names.arg = raw_data$Location)

Currently, R will either only show 8 of the 9 names or it will start repeating some of them and it looks very uneven. Is there a way to tell it to only show every 5th name?

Simple version:

If I have something like this:

barplot(c(1, 2, 3, 4, 2), names.arg = c('cow', 'horse', 'pig', 'raccoon', 'butterfly'))

Can I make a barplot that looks like:

| X
| X X
| X X X X


Just separate the plotting the the labeling.

barpos <- barplot(c(1, 2, 3, 4, 2))
axis(1, at=barpos[3], labels=("pig"))

The x value where each bar is drawn is returned from barplot.

Look what I can do!