Re: [R] two graphs in one figure?

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Thu, 10 Apr 2008 15:36:26 +0200

Dear Anne-Katrin,

You could use ggplot to do this. The example below works, although it generates some warnings.

library(ggplot2)
dataset <- data.frame(x = 0:55, y = rnorm(56, 10), z = runif(56, 9, 11))
ggplot(data = dataset) + geom_bar(aes(x = factor(x), y = y), position = "dodge") + geom_line(aes(x = x, y = z))

HTH, Thierry



ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx_at_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

-----Oorspronkelijk bericht-----
Van: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] Namens Anne-Katrin Link Verzonden: donderdag 10 april 2008 15:18 Aan: R Help
Onderwerp: [R] two graphs in one figure?

Dear all,

how can I plot a line graph and a bar graph in one single figure? I tried to combine "barplot" and "plot". Even though they both have the same x-values (1 to 55),  it just doesnt look as if they match in their scale (the barplot is much wider than the "plot"....even though I tried to put limits on the x-axis).
Here is an example of what I did:

barplot(y, xaxt="n",yaxt="n",ylim=c(-1,45), xlim=c(1,55)) ...
par(new=TRUE)
plot(x, ynew, lty=2, type="l", ylim=c(0,15), xlim=c(1,55))

Another question: how can I make sure that the "0"-values from the barchart are displayed as well?

Thank you so much!

Anne-Katrin     

-- 
Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! 
http://games.entertainment.gmx.net/de/entertainment/games/free

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 10 Apr 2008 - 13:54:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Apr 2008 - 16:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive