On 10/31/2011 08:13 AM, Alaios wrote:
> Dear all,
> I am plotting 3 plots into the same x and y axis.
> I want the first one to be painted red with a continuous line
> The second one green with a continuous line
> and the third one blue with a continuous line
>
> plot(max_power(data),ylim=c(-120,-20))
>     par(new=T)
>     plot(min_power(data),ylim=c(-120,-20))
>     par(new=T)
>     plot(mean_power(data),ylim=c(-120,-20))
>     par(new=F)
>
> Is it also a way to do that look more nice instead of having 6 lines of code?
>
> B.R
> Alex
>
>       [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help@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.

Hi,

I would use ggplot2:

library(ggplot2)

## Create some fake data
dat = data.frame(value = runif(10000), tstep = rep(1:100, each = 100))
head(dat)
# Compute powers per tstep
dat_power = ddply(dat, .(tstep), summarise, max_power = max(value),
                        min_power = min(value), mean_power = mean(value))
# Reorder dataset for ggplot
dat_ggplot = melt(dat_power, id.vars = c("tstep"))

## Make the plot
ggplot(aes(x = tstep, y = value, color = variable), data = dat_ggplot) +
geom_line()

To change the colors of the lines, take a look at ?scale_color_manual.

cheers,
Paul

-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770


        [[alternative HTML version deleted]]

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

Reply via email to