繁体   English   中英

更改散点图 Plot 点 Colors 与许多观察

[英]Changing Scatter Plot Point Colors with many observations

我目前正在对 Craigslist 上包含许多不同汽车的大型数据集进行主成分分析。 既然有这么多的观察,我想指出一些具体的汽车品牌,例如梅赛德斯-奔驰、福特或特斯拉。

我一直在 ggplot2 中执行以下操作:

manufacturer <- data[3] #Which is the labels for the manufacturers
manu.label <- unlist(manufacturer)

ggplot(plot.car.pca, aes(SCA.PCA1, SCA.PCA2, label = manu.label, color = manu.label) + 
geom_point() + 
geom_text(aes(label = manu.label), hjust = -0.01, vjust = 0)

这将产生以下 plot:

散点图

从图中可以看出,有很多制造商,但我只想突出其中一些,例如,散点图上的福特汽车点可能是绿色的,特斯拉可能是红色的,rest 可能是黑点. 我希望我已经提供了足够的信息,并且你们中的一些人可以在这里帮助我。

详细说明我的评论(以 mtcars 为例)

library(ggplot2)
dt <- mtcars

#create column with car name
dt$car <- rownames(dt)

#cars interested in
dt1 <- subset(dt, dt$car %in% c("Toyota Corolla", "Toyota Corona"))

#cars not interested in
dt2 <- subset(dt, !dt$car %in% dt1$car)

#plot with both (individual geom_points)
ggplot(dt2) + geom_point(aes(x = mpg, y = mpg)) + geom_point(data = dt1, aes(x = mpg, y = mpg, colour = car)) + geom_text(data = dt1, aes(x = mpg, y = mpg, label = car), hjust = 1, vjust = 1) + theme_bw() 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM