[R] Making two lines graph ...
Marc Schwartz
marc_schwartz at comcast.net
Sat Feb 24 16:44:54 CET 2007
Or a possible alternative still using matplot:
matplot(DF[, 3:4], type = "b", xaxt = "n", pch = c(21, 22),
col = "black", lty = c("dotted", "solid"),
ylab = "Y Vals", xlab = "Groups")
axis(1, at = 1:5, labels = as.character(DF$x.orig))
legend("topright", legend = c("Group 1", "Group 2"),
lty = c("dotted", "solid"), pch = c(21, 22))
See ?points for different point symbols (pch) if you prefer.
HTH,
Marc Schwartz
On Sat, 2007-02-24 at 08:08 -0500, jim holtman wrote:
> Does this do what you want?
>
>
> x <- "x.orig x.num y1 y2
> a 1 0.2 0.4
> b 2 0.1 0.1
> c 3 0.3 0.3
> d 4 0.3 0.15
> e 5 0.1 0.05"
> x.in <- read.table(textConnection(x), header=TRUE)
> plot(x.in$y2, type='l', ylim=range(x.in$y1, x.in$y2), xaxt='n', col='red',
> xlab='', ylab='y')
> lines(x.in$y1, lty=2, col='green')
> axis(1, labels=as.character(x.in$x.orig), at=seq(nrow(x.in)))
>
>
>
>
>
> On 2/24/07, Petar Milin <pmilin at gmail.com> wrote:
> >
> > Hello!
> > Can anyone help me to build a graph with the alphanumeric values on
> > x-axis, with two lines (preferably doted and solid, or similar) that
> > present values on y-axes. In a toy example, data frame could be like
> > this:
> > x.orig x.num y1 y2
> > a 1 0.2 0.4
> > b 2 0.1 0.1
> > c 3 0.3 0.3
> > d 4 0.3 0.15
> > e 5 0.1 0.05
> >
> > I can make graph only if I use values converted to numeric in "x.num",
> > but not original "X.orig":
> > matplot(dat$x.num, dat[, c("y1","y2")], type="b", lty=1, ylab="(1) y1,
> > (2) y2")
> >
> > Also, how to make doted and solid instead of coloured lines?
> >
> > Thanks in advance. Sincerely,
> > Petar M
> >
More information about the R-help
mailing list