[R] Bode plots in ggplot2
hadley wickham
h.wickham at gmail.com
Thu Feb 7 15:15:20 CET 2008
On Feb 7, 2008 5:19 AM, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:
> 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()
Although looking at the example, the y axes have different scales -
which you can't currently do in ggplot (although it definitely on the
drawing board). You might need to do:
bode <- ggplot(bode, aes(x = frequency, colour = system)) +
geom_line() + facet_grid(system ~ .) + scale_x_log10()
bode + aes(y = phase)
bode + aes(y = gain)
to make two separate plots, and then use grid to join them up on one
page (see the final chapter of the ggplot2 book)
Hadley
--
http://had.co.nz/
More information about the R-help
mailing list