Grouping points
'data.frame': 150 obs. of 5 variables:
$ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
$ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
$ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
$ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
my.pch <- 16:18
my.col <- c('orange','blue','green3')
plot(Sepal.Length ~ Petal.Length, data = iris,
type = 'p', xlab = 'Petal.Length', ylab = 'Sepal.Length',
pch = my.pch[iris$Species],
col = my.col[iris$Species])

Adding a legend
# Simple text
mtext <- 'Plot of Sepal & Petal length for all Species'
text(x = 1, y = 7.5, pos = 4,
labels = mtext,
col = 'red', cex = 1)
# Legend
my.text <- levels(iris$Species)
legend(x = 'bottomright', legend = my.text)
# Legend: Redo
plot(Sepal.Length ~ Petal.Length, data = iris,
type = 'p', xlab = 'Petal.Length', ylab = 'Sepal.Length',
pch = my.pch[iris$Species],
col = my.col[iris$Species])
legend(x = 'bottomright', legend = my.text, pch = my.pch, col = my.col)
Using locator
to position
plot(Sepal.Length ~ Petal.Length, data = iris,
type = 'p', xlab = 'Petal.Length', ylab = 'Sepal.Length',
pch = my.pch[iris$Species],
col = my.col[iris$Species])
legend(x = locator(1), legend = my.text, pch = my.pch, col = my.col)
legend(x = locator(1), legend = my.text, pch = my.pch, col = my.col, bty='n')
Add text
with locator
text(x = locator(1), labels = expression(R^2 == 0.85))