[R] Bode plots in ggplot2

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Feb 7 12:19:52 CET 2008


Tribo,

Suppose you dataset is called bode. Then "melt" it:

Melted <- melt(bode, id.var = c("frequency", "system")

Then you'll get something like.

frequency | system | variabele | value
0 | system 1 | phase | 0
0 | system 1 | gain | 100

then this line below should do the trick (untested)

ggplot(Melted, aes(x = frequency, y = value, colour = system)) +
geom_line() + facet_grid(system ~ .) + scale_x_log10()

HTH,

Thierry

PS read the posting guide. A small, reproducible sample of data and code
would make things easier for us.
 

------------------------------------------------------------------------
----
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 op inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Tribo Laboy
Verzonden: donderdag 7 februari 2008 11:57
Aan: r-help op r-project.org
Onderwerp: [R] Bode plots in ggplot2

Hello,

I am trying to figure out how to make a bode plot (a.k.a. bode
diagram) in ggplot2.

An example of such a diagram can be found here:

http://meweb.ecn.purdue.edu/~me475/ctm/freq/bode2.GIF

The example above shows the gain and phase characteristic of a linear
system.
In my case, I would like to compare visually several systems on the
same diagram.


The data in the data frame is arranged like this:

frequency | gain | phase | system
0.0 | 1.0 | 0.0 | system 1
0.5 | 1.2 | -0.1 | system 1
1.0 | 1 .4| -0.2 | system 1
.
.
0.0 | 2.2 | 0.0 | system 2
0.5 | 2.2 | -0.5 | system 2
1.0 | 2 .4| -0.6 | system 2
.
.
.

First problem is, I would expect I'll need to use layers (for each
"plot", "panel", "axes", whatever it is called)  in ggplot, but I
don't know how.
The second problem is that those two "panels" need to have a common
legend (or "key"), which says "system 1" "system 2" . And that doesn't
seem to be trivial either.

Any help appreciated,


Regards,

TL

______________________________________________
R-help op 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.



More information about the R-help mailing list