比较来自世界各地的卖家的域名和 IT 服务价格

改变点和颜色框架的颜色/椭圆围绕这一点

我想从我开始用户的事实开始 R 特别是这个网站,所以如果你需要一些东西可以在这里澄清,请告诉我! 我仍然不太了解一切,所以请不要犹豫 "dumb down", 越多越好。

问题:我想创造 PCA 描绘两组的图形 /在这种情况下,类型/. 我也想在他们周围绘制椭圆或框架。

幸运的是,我使用了这项任务 ggplot2!
但是,我无法改变点或椭圆的颜色/默认值之外的帧。

你能否在这件事上建议一些帮助?

请参阅下面的代码示例,这只是传统的数据集。 iris, 经常在例子中使用 PCA.


###load in plackages###
library/ggbiplot/
library/ggfortify/
library/cluster/

#my actual data is very similar to the iris data, though in my data the "Species" column is first
head/iris/
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
df <- iris[c/1, 2, 3, 4/]
autoplot/prcomp/df//
autoplot/prcomp/df/, data = iris, colour = 'Species'/ #pca graph with species depicted in different colors



autoplot/prcomp/df/, data = iris, colour = 'Species', shape='Species', frame=T/
已邀请:

龙天

赞同来自:

我做了一样 PCA


data<-iris
df<-iris[c/1, 2, 3, 4/]
PC<-prcomp/df/
PCi<-data.frame/PC$x,Species=data$Species/


现在您进行定期计划并更改参数
ggplot

, 照常


ggplot/PCi,aes/x=PC1,y=PC2,col=Species//+
geom_point/size=3,alpha=0.5/+ #Size and alpha just for fun
scale_color_manual/values = c/"#FF1BB3","#A7FF5B","#99554D"//+ #your colors here
theme_classic//


https://i.stack.imgur.com/RMdrH.png
此外,检查
scale_fill_manual

框架

EDIT

我认为添加框架应该更容易,在这里检查。
https://stats.stackexchange.co ... plot2
和这里
https://coderoad.ru/25449093/
另外,我还在思考 , 什么 ggbiplot 必须处理
scale_color_manual


scale_fill_manual

, 你能更新失败的问题吗?

卫东

赞同来自:

令人惊叹的酱!

答案在这些例子中没有完全隐藏,但我发现了 scale_color_manual 和 scale_fill_manual 完全包含我想要改变任何周到颜色的框架!


#using autoplot from earlier, I placed it into an object
a<-autoplot/prcomp/df/, data = iris, colour = 'Species', shape='Species', frame=T/
#then I added on scale_color_manual and scale_fill_manual with the wacky color combos that would never be publishable
a + scale_fill_manual/values = c/"#FF1BB3","#A7FF5B","#99554D"// + scale_color_manual/values = c/"black","white","orange"//


http://i.stack.imgur.com/U10mX.png
非常感谢您的帮助! 非常感谢这个小的事实 /或者相反,非常大/ 这个小组在这里!

要回复问题请先登录注册