How do i explicitly assign a specific color to a particular factor/group using the plot command? I have plot two datasets - each having two groups (A3 & A4). The only difference between them is that one of them have two rows (outlier) removed. However, the colors were completely different between the two datasets. And in each group, the colors are not distinct between the two groups. Please refer:
And this is my code:
d<-read.csv("data-outlier.csv",header=T)
par(mar=c(5,5.5,4,2)+0.1)
plot(
formula = Wealth ~ Age,
data = d,
pch = 20,
col = c('blue','red2'),
xlab = expression(Age),
ylab = expression(Income),
xlim=c(0,140),
las = 1,
cex = 1.5,
cex.axis = 1.6, cex.lab = 1.8,
bty = 'l'
)
A3 <- subset(d, Team=="A3")
A4 <- subset(d, Team=="A4")
rA3 <- lm(Wealth~Age, data=A3);
rA4 <- lm(Wealth~Age, data=A4);
abline(rA3, lty=3, col='blue')
abline(rA4, lty=3, col='red2')
legend(x = 'bottomright',
legend = c('A3','A4'),
col = c('blue','red2'),
pch = c(20,20),
bty = 'n')
I am sorry i do not know how to format this data into a vector to be put here, but here are the external links: 1. All data 2. 2 data removed
Is there a way to specify one color to one group besides plotting using "points" separately (and besides using ggplot)?
Thank you in advance!

