I am learning R and working with the Default dataset. My attempt is to graphically show a relationship between balance, income, and default cases. I have managed to put together a graph and now need assistance with coloring specific points.
Note: Please excuse me if this topic has been discussed before. I looked in the forum for a similar post but failed to find one.
Here is my code:
dataset(Default)
plot(Default$balance~Default$income, col=Default$student, las=1, xlab = "Income",
ylab="Balance", main="Income and balance effects on default
loans",pch=as.numeric(Default$default), cex = 0.7)
legend("topright",legend=unique(Default$default), title = "Default?", pch = c(1,2))
Could a member help me:
Edit: The Default dataset is in the ISLR package. Thank you @ richard for pointing this out.
Here is the answer for others to reference:
plot(Default$balance~Default$income, col=ifelse(Default$default == "Yes", "green",
Default$student), las=1, xlab = "Income", ylab="Balance", main="Income and balance
effects on default loans",pch=as.numeric(Default$default), cex = 0.7)
legend("topright",legend=unique(Default$default), title = "Default?", pch = c(1,2),
col = c("black", "green"))
legend("topleft", legend=unique(Default$student), title = "Student?",
col=c("black", "red"), pch=1)