sharing the x axis in two plots

47 views
Skip to first unread message

Sebastian Weber

unread,
Jul 29, 2010, 10:52:23 AM7/29/10
to ggp...@googlegroups.com
Hi!

I have two observables which depend on the same time variable. I would like to plot these in two separate plots, but stack these onto one another in order to share the x-Axis for the sake of saving some space. So in principle I could arrange my data-set such that I can get what I want by facetting. However, I want in one of the two plots to draw a line which is there as a guide to the eye. geom_abline would now draw this line in both facets which is wrong. Another option to generate two plots and merge them via grid.layout is not working, since I can not suppress the x-tick marks separately from the y tick marks. This then yields in too much space between the two plots. So this boils down to

1. can I make ggplot2 draw a reference line in only one of the facets?

- or -

2. can I somehow suppress only the x-tick marks?

Thanks a lot in advance!

Sebastian Weber

ONKELINX, Thierry

unread,
Jul 29, 2010, 11:03:43 AM7/29/10
to Sebastian Weber, ggp...@googlegroups.com
Hi Sebastian,

Here is an example of an abline only showing in one facet. You need a
data frame with the properties of the abline and the corresponding
factors of the facetting.

library(ggplot2)
test <- data.frame(A= rnorm(100), B = rnorm(100), C = rbinom(100, 1,
0.5))
ggplot(test, aes(x = A, y = B)) +
geom_point() +
facet_wrap(~C, ncol = 1) +
geom_abline(data = data.frame(I = c(0, NA), S = c(1, NA), C =
c(0, 1)), aes(intercept = I, slope = S))

Best regards,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry....@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey


________________________________

--
You received this message because you are subscribed to the
ggplot2 mailing list.
Please provide a reproducible example:
http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2


Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.

Sebastian Weber

unread,
Jul 29, 2010, 11:55:52 AM7/29/10
to ONKELINX, Thierry, ggp...@googlegroups.com
Great!

This works! thanks a lot!

Now, the next problem: How to have two y-labels? ylab(c("LABEL1", "LABEL2")) does not do the job. Any suggestions?

Sebastian
Reply all
Reply to author
Forward
0 new messages