0

I have seen previous advice on Stack Overflow relating to inserting axis breaks in histograms, for example, see here:

Break X Axis in R and Put a break in the Y-Axis of a histogram

However, applying the code given in these posts to my data has proved difficult. I am using R Studio (version 3.4.3) on a 64-bit Windows 10 machine. I am producing histograms to compare four foraging behavioural ethograms relating to three bird species.

The three species are denoted by the following initials: 'HG', 'GB' and 'LB'. An observation unit of 15 seconds (sec) per bird was used, with the following ethogram information collected for each subject: (a.) number of pecks, (b.) number of occasions food items were swallowed, (c.) number of paces ranked in 1 of 4 categories: 0 = none, 1 = 1–4, 2 = 5–10, 3 = >10. Mean walking rates were estimated by assigning the following number of paces to each rank: 1 = 2.5 paces, 2 = 7.5 paces, 3 = 15 paces, (d.) proportion of time spent stationary was ranked in one of four categories: 0 = none, 1 = 1–5 sec, 2 = 6–10 sec, 3 = 11–15 sec. Mean time spent stationary was estimated by assigning the following number of seconds to each rank: 1 = 2.5 sec, 2 = 7.5 sec, 3 = 12.5 sec. The data amount to a total of 2,329 bird-observations.

The behaviour data for each of the three species exists as individual datasets in R, entitled 'HGbehaviour', 'GBbehaviour' and 'LBbehaviour'. I also have a complete dataset entitled 'behaviour', which contains the 2,329 bird-observations across all three species.

I have no problem in producing 'standard' histograms for each species. For example, for species 'HG', the following code produces histograms in base R:

attach (HGbehaviour) 
hist (Nopecks) 
hist (Noswallows) 
hist (Nopaces) 
hist (Time_stationary)

However, the problems lie in attempting to compare histograms between species. This is at least partly compounded by the fact that the number of observations for each species is not the same (HG n = 1961; GB n = 255; LB n = 113).

I have found a way of limiting the x and y axes in order to compare histograms with fixed axes, for different species, with the following code:

hist (Nopecks, xlim = c (0,21), ylim = c (0, 1000))

But the problem I have is that, for HG, some of the frequencies are considerably higher. This means that I need to create breaks on the y axis. For some behaviours, I am likely to need breaks on the x axis also.

Here is some code that I have tried:

gap.barplot (HGbehaviour, gap =c (200, 250)), xlab= "No. pecks",
             ytics=c(0,5,10,15,20), ylab = "Frequency", 
             main = "HG no. pecks"

However, this produces error messages.

I have spent two days in front of my laptop attempting to remedy this, but to no avail.

Can someone advise please as to how to produce breaks in the x and y axes of my histograms?

user20650
  • 24,654
  • 5
  • 56
  • 91
  • 3
    hi @Brianna and welcome. In order to solve your problem, please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). also, please have a look at [this](https://stackoverflow.com/help/how-to-ask) on how to ask your questions. – huan Dec 14 '18 at 13:19
  • if you want to have a look at a [good example](https://stackoverflow.com/questions/53778775/adding-something-to-a-list-of-dates-in-a-column). short, reproducible, solved. – huan Dec 14 '18 at 13:22
  • this may be a copy and paste error, but the line `gap.barplot (HGbehaviour, gap =c (200, 250)), xlab= "No. pecks", ytics=c(0,5,10,15,20), ylab = "Frequency", main = "HG no. pecks"` has an extra incorrect closing bracket after the `c (200, 250)` – user20650 Dec 14 '18 at 15:24
  • this is an interesting question, but I think you might get better answers if you focus on "how can I best display these data to make the comparisons I want?" rather than "how do I break the axes"? As suggested by others, if you can post some representative data, someone might come up with a nice solution. – Ben Bolker Dec 14 '18 at 15:34

1 Answers1

0

Maybe try axis.breaks or gap.plot https://www.rdocumentation.org/packages/plotrix/versions/3.7-4/topics/axis.break

Using axis breaks is considered misleading by some. Hadley Wickham recommends using faceted plots instead.

Jason
  • 1