'Error in plot.xy(xy, type, ...) : invalid color name 'A'
I am working on a paper writing exercise and was provided the following R code to use analyze a given data set. It has worked perfectly until I reach this last step and then I receive this error and I'm not sure how/where I need to redefine the color as I need the scatter plot to be two different colors for the groups. Its the very last line that doesnt produce the needed graph. Thanks for the help.
dat<-read.table("F:/University/NSU_TEACHING/NEW_CORES/NEW_MARINE
GEOLOGY/NEW_MODULES_2015_7/Online_data/SANDS2.txt", header=F)
par(mfrow=c(1,2))
plot(dat$V2,col="blue",main="Median grain size" )
plot(dat$V3,col="red",main="Sorting Coefficient")
boxplot(dat$V2~dat$V1,main="Median grain size" )
boxplot(dat$V3~dat$V1,main="Sorting Coefficient")
hist(dat$V2,main="Median grain size")
hist(dat$V3,main="Sorting Coefficient")
hist(dat$V2,main="Median grain size",breaks=20)
qqnorm(dat$V2,main="Median Grain Size"); qqline(dat$V2)
qqnorm(dat$V3,main="Sorting Coefficient"); qqline(dat$V3)
shapiro.test(dat$V2)
shapiro.test(dat$V3)
ks.test(dat$V2[dat$V1=="A"],dat$V2[dat$V1=="B"])
hist(dat$V2[dat$V1=="A"])
hist(dat$V2[dat$V1=="B"])
fligner.test(dat$V2~dat$V1)
t.test(dat$V2~dat$V1)
boxplot(dat$V2~dat$V1,notch=T,main="Median grain size" )
plot(dat[,c(2,3)],col=dat[,1])
Data set if needed
#Group A = Beach sands, Group B = Offshore sands, Column 2 = Median grain size in mm., Column 3 = Sorting coefficient
A 0.333 1.08
A 0.340 1.08
A 0.338 1.09
A 0.333 1.10
A 0.323 1.13
A 0.327 1.12
A 0.329 1.13
A 0.331 1.13
A 0.336 1.12
A 0.333 1.14
A 0.341 1.14
A 0.328 1.15
A 0.336 1.15
A 0.327 1.16
A 0.329 1.16
A 0.330 1.16
A 0.323 1.17
A 0.328 1.17
A 0.332 1.17
A 0.331 1.18
A 0.326 1.18
A 0.333 1.18
A 0.330 1.19
A 0.336 1.19
A 0.327 1.20
A 0.324 1.21
A 0.332 1.21
A 0.322 1.22
A 0.329 1.22
A 0.325 1.24
A 0.328 1.26
A 0.322 1.27
A 0.318 1.22
A 0.330 1.17
B 0.339 1.12
B 0.346 1.12
B 0.350 1.12
B 0.352 1.13
B 0.341 1.15
B 0.347 1.15
B 0.337 1.16
B 0.343 1.16
B 0.340 1.17
B 0.346 1.17
B 0.349 1.17
B 0.339 1.18
B 0.342 1.18
B 0.346 1.18
B 0.351 1.18
B 0.340 1.19
B 0.344 1.19
B 0.333 1.20
B 0.337 1.20
B 0.339 1.20
B 0.342 1.20
B 0.339 1.21
B 0.340 1.21
B 0.341 1.21
B 0.335 1.22
B 0.337 1.22
B 0.340 1.22
B 0.343 1.22
B 0.334 1.22
B 0.348 1.22
B 0.337 1.22
B 0.342 1.23
B 0.334 1.24
B 0.340 1.24
B 0.342 1.24
B 0.331 1.25
B 0.336 1.25
B 0.341 1.25
B 0.334 1.26
B 0.337 1.27
B 0.339 1.27
B 0.330 1.28
B 0.334 1.28
B 0.332 1.29
B 0.330 1.31
B 0.334 1.31
B 0.340 1.21
Solution 1:[1]
From comments:
I suspect this is a stringsAsFactors=FALSE problem. If the guide was written for R 3.0 and you're using R 4.0 or higher, the encoding of that column will be different. Try adding stringsAsFactors = TRUE to your original read.table call, or change the last line to plot(dat[,c(2,3)],col=factor(dat[,1]))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dubukay |
