Rescale axis in grouped scatter plots with use of axes breaks

雨燕双飞 提交于 2019-12-11 04:58:21

问题


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

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

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.

Thanks


回答1:


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:

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")



回答2:


You could be using gap.plot() which is easily found by following the link on the axis.break help page. There is a worked example there.



来源:https://stackoverflow.com/questions/12427376/rescale-axis-in-grouped-scatter-plots-with-use-of-axes-breaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!