简体   繁体   English

将轴中断插入到R中的直方图中

[英]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 在R中断开X轴,在 直方图的Y轴中断开

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. 我在64位Windows 10计算机上使用R Studio(版本3.4.3)。 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'. 这三个种类用以下首字母表示:“ HG”,“ GB”和“ 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. 使用每只鸟15秒(秒)的观察单位,并为每位受试者收集以下人口统计图信息:(a。)啄的次数,(b。)吞咽食物的次数,(c。)步速在4个类别中排名1:0 =无,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. 通过为每个等级分配以下步数来估计平均步行速度:1 = 2.5步,2 = 7.5步,3 = 15步,(d。)固定花费的时间比例被归为以下四个类别之一:0 =无,1 = 1-5秒,2 = 6-10秒,3 = 11-15秒。 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. 通过为每个等级分配以下秒数来估算平均静止时间:1 = 2.5秒,2 = 7.5秒,3 = 12.5秒。 The data amount to a total of 2,329 bird-observations. 数据总计有2329例鸟类观测。

The behaviour data for each of the three species exists as individual datasets in R, entitled 'HGbehaviour', 'GBbehaviour' and 'LBbehaviour'. 这三个物种中每个物种的行为数据都作为R中的单独数据集存在,分别为“ HG行为”,“ GB行为”和“ LB行为”。 I also have a complete dataset entitled 'behaviour', which contains the 2,329 bird-observations across all three species. 我也有一个名为“行为”的完整数据集,其中包含所有三个物种的2329次鸟类观测。

I have no problem in producing 'standard' histograms for each species. 在为每个物种生成“标准”直方图时,我都没有问题。 For example, for species 'HG', the following code produces histograms in base R: 例如,对于物种“ HG”,以下代码在基数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). 每个物种的观测数量不同(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: 我发现了一种限制x和y轴的方法,以便使用以下代码比较不同物种的固定轴直方图:

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. 但是我的问题是,对于HG,某些频率要高得多。 This means that I need to create breaks on the y axis. 这意味着我需要在y轴上创建中断。 For some behaviours, I am likely to need breaks on the x axis also. 对于某些行为,我可能还需要在x轴上中断。

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? 有人可以建议我如何在直方图的x和y轴上产生中断吗?

Maybe try axis.breaks or gap.plot https://www.rdocumentation.org/packages/plotrix/versions/3.7-4/topics/axis.break 也许尝试axis.breaks或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. Hadley Wickham建议改用多面图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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