Reputation: 99428
I have a 100 2-dim points, which form a 100 by 2 matrix X, stored in a text file "data"
I have a 100-dim vector Y, which form the class labels (numerical from 1 to 3) of the 100 points, and is stored in a text file "labels".
In R, I was wondering how you would plot the 2-dim points in X, s.t. each point is represented by its class label instead of a dot and represented in a color of its class label (the color is same for points of the same class label, but different for points of different class labels)?
Thanks!
Upvotes: 0
Views: 4709
Reputation: 173577
To make Dirk happy, a non-ggplot answer:
x1 <- runif(100)
x2 <- runif(100)
y <- sample.int(3 , 100 , replace = T)
plot(x1,x2,type = "n")
text(x1,x2,labels = y,col = c('red','blue','green')[y])
Upvotes: 2
Reputation: 59970
Do you want to do something like this?
x1 <- runif(100)
x2 <- runif(100)
y <- sample.int(3 , 100 , replace = T)
df <- data.frame( x1,x2,y)
ggplot( df )+
geom_text( aes( x1 , x2 , label = y , colour = factor(y)))
Upvotes: 3