Skip to content
Prev 275423 / 398506 Next

Plot Legend

Glad to hear it worked for you.

There does seem to be some confusion on your end as to what the with()
command does, however. The following are all equivalent.

data(mtcars)
layout(matrix(1:4,2))

plot(mtcars$cyl, mtcars$mpg)
plot(mtcars[["cyl"]], mtcars[["mpg"]])
plot(mtcars[,"cyl"], mtcars[,"mpg"])
with(mtcars, plot(cyl, mpg))

In effect, with() lets you tell R, for this expression only, you can
look up column names as variables directly: for a long line, this just
clears the syntax up. If you've ever heard of the attach() command --
not recommended -- it's basically a nicely behaved local version
thereof.

If I'm reading your code correctly, it can all be written quite succinctly as:

with(dataset, {
plot ( Na, Kt, col = Drug, type = "p", pch = 20)
legend ("top", legend = unique (Drug), pch = unique(Drug))
legend ("bottom", legend = unique (Drug), pch =20, col =unique (Drug))
})

Though it seems like that second line isn't actually accurate to what
you plotted so you may with to remove it.

M
On Mon, Oct 24, 2011 at 4:30 PM, RMSOPS <ricardosousa2000 at clix.pt> wrote: