不幸的是,您链接到的代码不是独立的,但您所拥有的代码可能gap.plot()
无法按您预期的那样工作,因为您设置ylim
为覆盖整个数据范围而不是仅绘制部分。考虑以下情节:
如您所见,y 轴每 50 pg/ml 都有刻度线,但在 175 和 425 之间存在差距。所以数据范围(最接近 50)是c(0, 500)
,但 y 轴的范围是c(0, 250)
- 就是这样200 和 250 的刻度线被视为 450 和 500 的刻度线。
该图是使用您的代码的以下修改版本生成的:
## 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")