Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m using R studio and I\'m trying to do a plot with the data. I was trying to

ID: 3231107 • Letter: I

Question

I'm using R studio and I'm trying to do a plot with the data. I was trying to make the graph so that ant.mass was my response varaible and head.width was my explanatory variable. I also wanted to distinguish observations by direction (A and D) with different colors.

This is the command I put into r: plot(ant.mass~head.width,col=c("red","blue")[direction]). Every time I put the command in though, my points are non existent. The only thing I see are axis labels. Does anyone know why this is?

head.width ant.mass direction 1.26 9.8 A 1.34 7.1 A 1.34 7.15 A 1.34 7.2 A 1.36 7.6 A 1.36 7.7 A 1.36 9.8 A 1.4 9.1 A 1.43 5.1 D 1.43 5.7 D 1.43 9.15 A 1.43 9.9 A 1.47 5.5 D 1.47 9.2 A 1.47 11.2 A 1.47 11.8 A 1.51 6.1 D 1.51 6.9 D 1.51 10.9 A 1.54 5.7 D 1.54 6.3 D 1.54 6.8 D 1.54 7 D 1.54 7.1 D 1.54 10.8 A 1.54 10.9 A 1.54 14 A 1.58 6.7 D 1.58 6.85 D 1.58 7.2 D 1.58 10.85 A 1.58 11 A 1.58 11.8 A 1.58 12 A 1.58 12.8 A 1.62 6.9 D 1.62 7 D 1.62 8.2 D 1.62 11.9 A 1.62 14.1 A 1.65 8.2 D 1.65 9.8 D 1.65 14 A 1.69 6 D 1.69 7.8 D 1.69 8.5 D 1.69 9.6 D 1.73 9.3 D 1.73 10.2 D 1.73 14 A 1.75 9.3 D 1.75 10.25 D 1.75 10.5 D 1.75 14.9 A 1.75 15 A 1.75 15.9 A 1.75 16.1 A 1.78 8.8 D 1.78 9 D 1.78 11.2 D 1.78 16.3 A 1.78 17.2 A 1.82 9 D 1.82 11.5 D 1.82 12.1 D 1.82 16.1 A 1.84 10 D 1.87 13 D 1.87 20.9 A 1.9 14 D 1.9 18.5 A 1.9 19 A

Explanation / Answer

First store the data in a data frame say "data".

Then store the color vector in a variable say "redblue".

redblue <- c("red","blue")

Then call the plot function as

plot(ant.mass~head.width,data,col=redblue[data$direction])