Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

r - How to plot points using their class labels?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)))

plot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...