[R] two graphs in one figure?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Apr 10 15:36:26 CEST 2008

Dear Anne-Katrin,

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

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



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
tel. + 32 54/436 185
Thierry.Onkelinx op 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 op r-project.org [mailto:r-help-bounces op 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))
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!

Psst! Geheimtipp: Online Games kostenlos spielen bei den GMX Free Games! 

	[[alternative HTML version deleted]]

More information about the R-help mailing list