使用轴中断重新调整分组散点图中的轴 [英] Rescale axis in grouped scatter plots with use of axes breaks

查看:50
本文介绍了使用轴中断重新调整分组散点图中的轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中绘制的某些类型图表的数据,

The data for some of these types graphs that I'm graphing in R,

http://graphpad.com/faq/images/1352-1(1).gif

具有超出范围的异常值,我不能仅仅排除它们.我尝试使用 plotrix 中的 axis.break() 函数,但该函数不会重新缩放 y 轴.它只是在轴上放置一个中断标记.这样做的目的是能够在一个图框中显示两组的中位数、数据点和异常值.从本质上讲,远离大多数的数据点占据了一大块空间,而大多数点都被压扁了,没有显示出太大的差异.代码如下:

has outliers that are way out of range and I can't just exclude them. I attempted to use the axis.break() function from plotrix but the function doesn't rescale the y axis. It just places a break mark on the axis. The purpose of doing this is to be able to show the medians for both groups, as well as the data points, and the outliers all in one plot frame. Essentially, the data points that are far apart from the majority is taking up a chunk of space and the majority of points are being squished, not displaying much differences. Here is the code:

https://gist.github.com/9bfb05dcecac3ecb7491

任何建议都会有所帮助.

Any suggestions would be helpful.

谢谢

推荐答案

不幸的是,您链接到的代码不是独立的,但可能是您拥有的用于 gap.plot() 的代码无法按预期工作,因为您将 ylim 设置为覆盖整个数据范围,而不仅仅是绘制的部分.考虑下面的图:

Unfortunately the code you link to isn't self-contained, but possibly the code you have for gap.plot() there doesn't work as you expect because you are setting ylim to cover the full data range rather than the plotted sections only. Consider the following plot:

如您所见,y 轴每 50 pg/ml 有一个刻度线,但在 175 和 425 之间存在差距.因此数据范围(到最接近的 50)为 c(0, 500) 但是 y 轴的范围是 c(0, 250) - 只是 200 和 250 的刻度线被视为 450 和 500 的刻度线.

As you can see, the y axis has tickmarks for every 50 pg/ml, but there is a gap between 175 and 425. So the data range (to the nearest 50) is c(0, 500) but the range of the y axis is c(0, 250) - it's just that the tickmarks for 200 and 250 are being treated as those for 450 and 500.

此图是使用以下修改后的代码生成的:

This plot was produced using the following modified version of your code:

## made up data
GRO.Controls <- c(25, 40:50, 60, 150)
GRO.Breast <- c(70, 80:90, 110, 500)

##Scatter plot for both groups
library(plotrix)
gap.plot(jitter(rep(0,length(GRO.Controls)),amount = 0.2), GRO.Controls,
         gap = c(175,425), xtics = -2, # no xtics visible
         ytics = seq(0, 500, by = 50),
         xlim = c(-0.5, 1.5), ylim = c(0, 250), 
         xlab = "", ylab = "Concentrations (pg/ml)", main = "GRO(P=0.0010)")
gap.plot(jitter(rep(1,length(GRO.Breast)),amount = 0.2), GRO.Breast,
         gap = c(175, 425), col = "blue", add = TRUE)

##Adds x- variable (groups) labels
mtext("Controls", side = 1, at= 0.0)
mtext("Breast Cancer", side = 1, at= 1.0)

##Adds median lines for each group
segments(-0.25, median(GRO.Controls), 0.25, median(GRO.Controls), lwd = 2.0)
segments(0.75, median(GRO.Breast), 1.25, median(GRO.Breast), lwd = 2.0, 
    col = "blue")

这篇关于使用轴中断重新调整分组散点图中的轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆