简体   繁体   中英

Inserting axis breaks into histograms in R

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM