[R] lineplot in ggplot2 with different colour and linetype
vistocco at unicas.it
Wed Feb 18 21:14:09 CET 2009
> Hi list,
> I would like to use ggplot2 in creating a line plot with 4 lines (groups), 2
> of which I want in colour and the remaining two as dotted lines.
> ### R code ###
> ### create data ####
> vals <- rnorm(400)
> div<- c(rep("A",100),rep("B",100),rep("C",100),rep("D",100))
> n<- rep(1:100,4)
> df<- data.frame(div= as.factor(div),vals=vals,n=n)
> ### ggplot function ####
> qplot(x=n,y=vals, colour = div ,geom = "line",data=df)
> What I would like to see is a line plot where I can have lines for groups A,
> and B in colour and lines for C and D in dotted and dashed respectively.
ggp <- ggplot(aes(x=n,y=vals, colour=div, linetype=div), data=df) +
ggp + scale_colour_manual(values = c("red","blue","black","black")) +
scale_linetype_manual(values = c(1,1,3,2))
> Also, I would like to know how I can draw two lines (groups C and D) which
> are both dotted.
For graphic specifications see Hadley' instructions:
> Harsh Singhal
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> 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