1

I am utilising ggplot2 within R to create barplot visualisations.

I have two variable columns:

  • Strength (75 observations) sorted from highest to lowest
  • Rank - The corresponding rank (1 being the highest, 75 being the lowest) of the above strength value

I have plotted these variables within a bar graph to show the distribution of strength values from highest to lowest ranked.

However, I am having difficulty with some of the bars being of different widths. I am using the following code:

a <- ggplot(data = mydata, aes(y = Strength, x = Rank))

a + geom_bar(stat="identity", width = .75, fill = "grey75") + 
theme(axis.text.x = element_text(angle = -270, colour="black", vjust=.5),
axis.title.x = element_blank(), axis.title.y = element_blank(),
axis.ticks.y = element_blank(), axis.ticks.x = element_blank(), 
axis.text.y =  element_blank(), panel.background = element_blank()) +
geom_text(aes(label = floor(Strength)),angle = -270, hjust = -.1)

This returns the following image:

bar plot

As you can see the bars at particular locations are wider for some reason. Is there anyway I can fix this? I have played around with the position functions to no avail.

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
ap123
  • 31
  • 1
  • 5
  • 1
    I'm guessing the main problem is just low resolution. If you made the image bigger, or made it using `pdf()` and zoomed in, I suspect you'd see that the bars are equal length. – Sam Dickson Feb 12 '14 at 13:32
  • 1
    Open a plot window using `windows()`, make your plot, and pull the side of the window to adjust the width, and you will find that you can create any 'weird stripe pattern'. I believe this is just an artefact from how the plot is rendered on your screen. Someone else can probably provide a more technically accurate description of the phenomenon. – Henrik Feb 12 '14 at 13:35
  • I had this same issue where there was missing data. [This answer](http://stackoverflow.com/q/11020437/1290485) helped me. – Climbs_lika_Spyder Oct 11 '16 at 14:12
  • Does this answer your question? [Preventing incosistent spacing/bar widths in geom\_bar with many bars](https://stackoverflow.com/questions/37547223/preventing-incosistent-spacing-bar-widths-in-geom-bar-with-many-bars) – tjebo Nov 23 '21 at 22:18

1 Answers1

0

What you are seeing here is called a Moiré pattern http://en.wikipedia.org/wiki/Moir%C3%A9_pattern

As suggested in the comments the resolution is the issue. Zoom in enough and you will find the bar widths are uniform. How much is enough will depend on your device parameters, screen etc. Indeed zooming in or out will probably create other stripy effects.

nstjhp
  • 528
  • 6
  • 12