split/discontinuous axis?

14,580 views
Skip to first unread message

Aaron Mackey

unread,
Jan 11, 2010, 7:52:38 AM1/11/10
to ggp...@googlegroups.com
Is there a scale_discontinuous() or somesuch in which I can specify two ranges, and a fraction of the axis for which each range is to be used?  I have cases where the data is essentially bimodal, with a large gap between; I'd rather not waste all that whitespace.  I can split the data into two plots/facets, but I think that misconstrues the point.  This also occurs when one wants to co-plot outliers while still being able to see the spread of the main data.

Thanks,
-Aaron

Luciano Selzer

unread,
Jan 11, 2010, 9:13:28 AM1/11/10
to Aaron Mackey, ggp...@googlegroups.com
Hi Aaron, Hadley will be able to confirm o deny this but I think that's not possible with ggplot.
Luciano


2010/1/11 Aaron Mackey <ama...@virginia.edu>
Is there a scale_discontinuous() or somesuch in which I can specify two ranges, and a fraction of the axis for which each range is to be used?  I have cases where the data is essentially bimodal, with a large gap between; I'd rather not waste all that whitespace.  I can split the data into two plots/facets, but I think that misconstrues the point.  This also occurs when one wants to co-plot outliers while still being able to see the spread of the main data.

Thanks,
-Aaron


--
You received this message because you are subscribed to the ggplot2 mailing list.
To post to this group, send email to ggp...@googlegroups.com
To unsubscribe from this group, send email to
ggplot2+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2

hadley wickham

unread,
Jan 11, 2010, 9:31:17 AM1/11/10
to Luciano Selzer, Aaron Mackey, ggp...@googlegroups.com
Correct, it's not possible. I'm not a big fan of this type of display
because I think it is visually distorting. I think it's much more
appropriate to show two plots - one of all the data, and one of just
the small values. That way you can see how much the large values
dominate the smaller ones.

Hadley

--
http://had.co.nz/

Aaron Mackey

unread,
Jan 11, 2010, 9:52:47 AM1/11/10
to hadley wickham, Luciano Selzer, ggp...@googlegroups.com
for the mixture distribution, I'm swayed to agree.  For the case where there are a few (in my case, just one) outliers, I'd like to be able to visualize as well as possible the distribution of the non-outliers, while still representing in some way the values of the outliers.  One way is with a figure caption that simply lists the (x, y) values/tuples of the outliers left off the plot.

Suggestions are welcome.  And thanks for a great graphics library!

-Aaron

David Duneau

unread,
Sep 14, 2015, 7:58:09 AM9/14/15
to ggplot2, luciano...@gmail.com, ama...@virginia.edu
Hello,

Is it still true that we cannot use ggplot2 to create graph with broken axis? (most discussion about that are fairly old) 

I totally understand the argument about distorting the data representation, however, there are examples where it is the other way around (e.g. when one got some zero).
I would like to be able to keep the factors that are zero in the same graph than the factors with no zero. (and I would like to keep using this handy package :). Without broken axis, the info "zero" (i.e. no success), change the representation of the difference between the other factors.

Thanks for your time.
Best,
David

Brian

unread,
Sep 14, 2015, 8:43:55 AM9/14/15
to David Duneau, ggplot2, luciano...@gmail.com, ama...@virginia.edu
Hi David,

I believe that is still true, and will likely remain that way. I think
it would be a good exercise to fish this list for
alternatives/solutions. For this though we need code :).

Could you please provide an example where it would be advantageous
(considering good plotting principles) to have a discontinuous axis?

Cheers,
Brian
> > 2010/1/11 Aaron Mackey <ama...@virginia.edu <javascript:>>
> >>
> >> Is there a scale_discontinuous() or somesuch in which I can
> specify two
> >> ranges, and a fraction of the axis for which each range is to
> be used? I
> >> have cases where the data is essentially bimodal, with a large
> gap between;
> >> I'd rather not waste all that whitespace. I can split the data
> into two
> >> plots/facets, but I think that misconstrues the point. This
> also occurs
> >> when one wants to co-plot outliers while still being able to
> see the spread
> >> of the main data.
> >>
> >> Thanks,
> >> -Aaron
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the ggplot2
> >> mailing list.
> >> To post to this group, send email to ggp...@googlegroups.com
> <javascript:>
> >> To unsubscribe from this group, send email to
> >> ggplot2+u...@googlegroups.com <javascript:>
> >> For more options, visit this group at
> >> http://groups.google.com/group/ggplot2
> <http://groups.google.com/group/ggplot2>
> >
> >
> > --
> > You received this message because you are subscribed to the
> ggplot2 mailing
> > list.
> > To post to this group, send email to ggp...@googlegroups.com
> <javascript:>
> > To unsubscribe from this group, send email to
> > ggplot2+u...@googlegroups.com <javascript:>
> > For more options, visit this group at
> > http://groups.google.com/group/ggplot2
> --
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google
> Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ggplot2+u...@googlegroups.com
> <mailto:ggplot2+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Arne Wichmann

unread,
Jul 28, 2016, 6:56:07 AM7/28/16
to ggplot2, david....@gmail.com, luciano...@gmail.com, ama...@virginia.edu
Hi Brian!

While digging around for a solution to a problem of mine i found this thread and thought i might provide you with an example of mine, where some kind of discontinuous axes would be a great advantage. 
(Here is my question on StackOverflow: http://stackoverflow.com/questions/38610692/plot-sparse-data-with-hexadecimal-labels-using-ggplot2 , where i am looking for an elegant/integrated solution...)

require(ggplot2)
df <- data.frame(src = round(c(0x10000:0x10100,runif(100, 0x1000,0x100000))), dst = round(c(0x11000:0x11100,runif(100,0x1000,0x100000))))
ggplot(df, aes(x = factor(src), y = factor(dst))) + geom_point()

I would hope that some kind of discontinuous axes would give me readable and sanely distributed labels... - Although, using the factor approach and an even more sophisticated breaks function (see my answer to the stackoverflow problem), along with a patched version of a discrete scale with support for minor breaks might also work...

Greetings,
Arne

Brian

unread,
Jul 28, 2016, 7:53:20 AM7/28/16
to Arne Wichmann, ggplot2, david....@gmail.com, luciano...@gmail.com, ama...@virginia.edu
Hi Arne,

when not doing things as factors but letting R convert to the numeric
representation, it doesn't look the same. The problem with this thread
is the same. My preference is to work up the data and present it as
facets (facet_[wrap|grid](~variable, scale="free")). This is what I
would recommend here.

Hex labels on the other hand are easy. I would work with the numbers and
just play with the labels. Therefore:

require(ggplot2)
df <- data.frame(src = round(c(0x10000:0x10100,runif(100,
0x1000,0x100000))),
dst =
round(c(0x11000:0x11100,runif(100,0x1000,0x100000))))

hexlabels <- function(x)
sprintf("0x%s", as.character.hexmode(x))

ggplot(df, aes(x = src, y = dst)) +
geom_point() +
scale_x_continuous(labels = hexlabels) +
scale_y_continuous(labels = hexlabels)

Tip: apropos("hex")

Cheers,
Brian
> > To post: email ggp...@googlegroups.com <javascript:>
> > To unsubscribe: email ggplot2+u...@googlegroups.com <javascript:>
> > More options: http://groups.google.com/group/ggplot2
> <http://groups.google.com/group/ggplot2>
> >
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "ggplot2" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to ggplot2+u...@googlegroups.com <javascript:>
> > <mailto:ggplot2+u...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.

Brett Ginsburg

unread,
Feb 12, 2020, 6:38:03 AM2/12/20
to ggplot2

This is a very old thread, but I am searching for a solution to this same problem.  Here is my use case: I am a pharmacologist, and I need to plot dose-effects. It is accepted practice to have a discontinuous x-axis in order to break the continuity between the vehicle and active doses.  The reason being that vehicle does not conform to the axis label (e.g. Drug Dose (mg/kg), as it is not a dose of Drug) and does not really represent the position it occupies on the axis (because doses are typically plotted on a log-transformed axis and so vehicle - essentially ZERO dose - has no transformation or position on the axis).
Reply all
Reply to author
Forward
0 new messages