如何用R中断Y轴制作箱形图

时间:2022-05-18 14:58:12

This is a sample of my data. It's a tab delimited file with a header.

这是我的数据样本。它是带有标题的制表符分隔文件。

X1      X2      X3      X4
1.3     0.5     0.1     1
NA      0.3     0.4     3
NA      0.2     0.3     0.3
NA      0.1     3       0.2
NA      27      5       56
NA      NA      10      0.01

I would like to get a boxplot from this data. The problem is that I want to interrupt the plot at 10 and 50 on Y-axis. I want a bigger plot size before 10 and a smaller plot size after that. I don't know how to plot with 2 gaps in Y-axis. I tried with axis.break and gap.boxplot but as my programming skills with R are very limited so I am unable to use both of these methods properly. I'd be grateful for any hints to accomplish this?

我想从这些数据中得到一个箱线图。问题是我想在Y轴上以10和50中断绘图。我希望在10之前有更大的地块尺寸,之后需要更小的地块尺寸。我不知道如何在Y轴上绘制2个间隙。我尝试使用axis.break和gap.boxplot,但因为我对R的编程技巧非常有限,所以我无法正确使用这两种方法。我会很感激有任何提示可以实现这一目标吗?

1 个解决方案

#1


1  

I'm not really clear on what you want, and what you mean by "bigger plot size before 10 and a smaller plot size after that". Do you mean different scales? That is a bad idea, I think, and I don't believe it would be straightforward.

我不是很清楚你想要什么,你的意思是“10之前更大的地块尺寸和之后更小的地块尺寸”。你的意思是不同的尺度吗?我认为这是一个坏主意,我不相信这会是直截了当的。

Here's how to break the axis twice (I'm guessing on the regions to exclude):

这是如何打破轴两次(我猜测要排除的区域):

library(plotrix)
library(reshape2)
a <- read.table(textConnection("X1 X2 X3 X4
        1.3 0.5 0.1 1
        NA 0.3 0.4 3
        NA 0.2 0.3 0.3
        NA 0.1 3 0.2
        NA 27 5 56
        NA NA 10 0.01"),sep=" ",header=T)
am <-melt(a) #from reshape2 - allows categorical variables to be in one column
gap.boxplot(am$value ~ am$variable, #means the values are plotted againsy variable
gap=list(top=c(30,50),bottom=c(10,24)), #specifies regions of Y axis to exclude
axis.labels=T) #should label all the Y axis, doesn't seem to work well

如何用R中断Y轴制作箱形图

#1


1  

I'm not really clear on what you want, and what you mean by "bigger plot size before 10 and a smaller plot size after that". Do you mean different scales? That is a bad idea, I think, and I don't believe it would be straightforward.

我不是很清楚你想要什么,你的意思是“10之前更大的地块尺寸和之后更小的地块尺寸”。你的意思是不同的尺度吗?我认为这是一个坏主意,我不相信这会是直截了当的。

Here's how to break the axis twice (I'm guessing on the regions to exclude):

这是如何打破轴两次(我猜测要排除的区域):

library(plotrix)
library(reshape2)
a <- read.table(textConnection("X1 X2 X3 X4
        1.3 0.5 0.1 1
        NA 0.3 0.4 3
        NA 0.2 0.3 0.3
        NA 0.1 3 0.2
        NA 27 5 56
        NA NA 10 0.01"),sep=" ",header=T)
am <-melt(a) #from reshape2 - allows categorical variables to be in one column
gap.boxplot(am$value ~ am$variable, #means the values are plotted againsy variable
gap=list(top=c(30,50),bottom=c(10,24)), #specifies regions of Y axis to exclude
axis.labels=T) #should label all the Y axis, doesn't seem to work well

如何用R中断Y轴制作箱形图