0

I have two datasets, that I'd like to see on a single scatterplot with a single axis. One dataset has Y values ranging from 0 to 0.0006, the other between 0 and 1.

Each dataset has 50 entries.

In R, is there a way of changing the scale of the y axis at the 0.0006 mark to show detail in both halves of the graph, e.g., the range of 0 - 0.0006 and 0.0006 - 1 would be the same size on the graph.

Zack Newsham
  • 2,810
  • 1
  • 23
  • 43
  • This might be useful: http://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis – Mike H. Aug 11 '16 at 13:45
  • @MikeyMike - I should have stated in the question that I'm using a scatterplot, with too much data for a table – Zack Newsham Aug 11 '16 at 13:48
  • Are you open to facetting the plot? Having one facet be your very small values and the other, the rest? – Mike H. Aug 15 '16 at 21:12
  • @MikeyMike, I'm not sure what facetting is in this context. The problem is that data from one set could potentially span both ranges, what I might end up doing is limiting the lower range to 0.0000006 or something, values below that arent really of interest as they are basically 0. – Zack Newsham Aug 17 '16 at 17:59

3 Answers3

0

I did this using a log scale, this is a sample dataset, which doesnt go all the way to 1 but taps out around 0.07.

I'm still open to other techniques as this one gives too much emphasis to the 0.0006-0 range.

enter image description here

Zack Newsham
  • 2,810
  • 1
  • 23
  • 43
0

You can scale your data for plotting, then call axis twice:

y1<-runif(50,0,0.0006)
y2<-runif(50,0.0006,1)
x<-runif(50)

y1.scaled<-y1*(0.5/0.0006)
y2.scaled<-(y2-0.0006)*(1-0.5)/(1-0.0006) + 0.5

plot(c(0,1),c(0,1),col=NA,yaxt='n',ylab="",xlab="")

  points(x,y1.scaled,pch=20,col="red")
  points(x,y2.scaled,pch=21,col="black")

axis(2,at=seq(0,0.5,length.out = 3), labels = c(0,0.0003,0.0006), col="red")
axis(2,at=seq(0.5,1,length.out = 3), labels = seq(0.0006,1,length.out=3))

See this post for how to re-scale a set of numbers with a known min and max to any other min and max: How to scale down a range of numbers with a known min and max value

Community
  • 1
  • 1
0

Assuming you have two different datasources (and that values from either source can be <0.0006) we could combine them, create an indicator for whether or not the value is <0.0006, and then use a facet_wrap with free scales. Something like this:

library(ggplot2)
set.seed(1)
y1<-runif(50,0,0.0006)
y2<-runif(50,0,1)
x<-1:50
df<-as.data.frame(rbind(cbind(y1,x),cbind(y2,x))) #Combine data
df$y1 <- as.numeric(as.character(df$y1))
df$x <- as.numeric(as.character(df$x))
df$group <- (df$y1 <= 0.0006) #Create group

#ggplot with facet
ggplot(data=df) + geom_point(aes(y=y1,x=x)) + facet_wrap(~grp,scales="free")

enter image description here

Mike H.
  • 13,960
  • 2
  • 29
  • 39