0

Gray and black dots appear in the plot in relation to female (gray) and black (male). The col argument specifies color based on gender type. However, the bracket syntax looks to be randomly thrown in the col argument. Where can this be found as i was unable to find it in the documentation?

plot(surveyNA$Height ~ surveyNA$Wr.Hnd, col = c("gray", "black")[as.numeric(surveyNA$Sex)], pch = 16, xlab = "Writing handspan", ylab= "Height")

Matthew
  • 45
  • 1
  • 9
  • 1
    Welcome to Stack Overflow. Please review [how to ask](https://stackoverflow.com/help/how-to-ask) questions, and what you need to do in order to provide a [minimal reproducible example/attempt](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). To start, you should use proper code formatting and give your question a meaningful title. Explicitly explain what you're trying to do and what failed in the main body of your question. – Maurits Evers Oct 11 '19 at 04:48
  • 1
    Try running `c("gray","black")[as.numeric(surveyNA$Sex)]` on its own and comparing it to `surveyNA$Sex`. – Marius Oct 11 '19 at 05:05
  • See how objects of class `"factor"` (in this case the column `Sex`) are coded in R. They are coded as consecutive 1-based integers. So `c("gray", "black")` is being subset by a vector of 1's and 2's. – Rui Barradas Oct 11 '19 at 17:58
  • I appreciate the posts. I know what its doing, but would have not figured it out without the syntax being shown. I typically look at the documentation for syntax and in this particular case did not find the [ ] for col. I'm thinking ahead for other similar scenarios, where can these sorts of syntax be found. It read just fine though. – Matthew Oct 11 '19 at 22:08

0 Answers0