Re: [R] Bode plots in ggplot2

From: hadley wickham <h.wickham_at_gmail.com>
Date: Thu, 7 Feb 2008 08:15:20 -0600

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/

______________________________________________
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 07 Feb 2008 - 14:20:30 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 Fri 08 Feb 2008 - 16:30:12 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