points() Function not Transferring Inputs

Hi,

I've written codes for editing the color and shape of some data points. However, the codes do not transfer to the scatterplot itself. What am I doing wrong?

elk <- structure(list(height = c(69.3, 69.3, 87.7, 99.8, 69.3, 84.1, 89.4, 91.9, 116.6, 104.7, 129.9, 94.6, 115.5, 138.4, 138.4, 127.5, 175.1, 164.3, 204.5, 183.6), antler = c(24.8, 34.5, 53.5, 58.3, 61.2, 67.3, 72.2, 81.5, 86.6, 91.4, 99.3, 101.5, 107.8, 115.7, 123.3, 128.5, 131.4, 162.6, 197.5, 239.1), species = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 1L, 2L), .Label = c("alces", "megaloceros", "unknown"), class ="factor")), class = "data.frame", row.names = c(NA, -20L))
elk$logy <- log(elk$antler)
elk$logx <- log(elk$height)
mdat <- data.frame(elk$points)
plot(elk$logx, elk$antler,
     xlab="Log Shoulder height (cm)",
     ylab="Log Antler length (cm)")
points(elk, mdat$sites, pch= c(16, 18, 22), col= c("red", "blue", "green3"))
legend("bottomright", legend=c("Unknown", "Alces", "Megaloceros"),
       pch= c(16, 18, 22), col=c("red", "blue", "green3"))

I've changed the column name:

mdat <- data.frame(elk$sites)

However, it still doesn't change the ascetics of the points

points(elk, mdat$sites, pch= c(16, 18, 22), col= c("red", "blue", "green3"))

Log transform

elk$logy <- log(elk$antler)
elk$logx <- log(elk$height)

Edit points

mdat <- data.frame(elk$species)
use.col <- ifelse(mdat$elk.species == "unknown", "red",
ifelse(mdat$elk.species == "alces", "blue",
ifelse(mdat$elk.species == "megaloceros", "green3", "NA")))
use.pch <- ifelse(mdat$elk.species == "alces", "x",
ifelse(mdat$elk.species == "megaloceros", "+", "*"))

Plot

plot(elk$logx, elk$antler,col = use.col, pch= use.pch,
xlab="Log Shoulder height (cm)",
ylab="Antler length (cm)")

Legend

legend("bottomright", legend=c("Other Species", "Alces", "Megaloceros"),
pch= c(8, 4, 3), col=c("red", "blue", "green3"))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.