将主成分分析绘制成离散的颜色代码,而不是连续的
Plotting Principal Component Analysis to a discrete color code, rather than continuous
我正在尝试根据数据在此处绘制主成分分析的结果,并将年龄作为颜色编码因素绘制到图上(如 link 中所附图片所示)
我想通过分组年龄范围而不是连续的颜色范围来改善视觉效果。例如,我想要三种颜色 group1 为 0-25 岁,group2 为 26 至 50 岁,group3 为 51+。有没有办法可以操纵这段代码来做到这一点?我试着在网上寻找这个,但我仍然不确定如何为这个代码集做这个。
# Plot the PCA with color coding of age
fviz_pca_ind(proteome_pr, geom.ind = "point", pointshape = 21,
pointsize = 2,
fill.ind = prot_subjectID$Age,
col.ind = "black",
pallette = "jco",
label = "var",
col.var = "black",
repel = TRUE,
legend.title = "Age") +
ggtitle("Proteome Data and Age Correlation") + theme(plot.title = element_text(hjust = 0.5))
Image of the generated figure
根据@MrFlick 的建议,您可以使用以下代码:
fviz_pca_ind(proteome_pr, geom.ind = "point", pointshape = 21,
pointsize = 2,
fill.ind = cut(prot_subjectID$Age, breaks = 10), # Here you can create groups.
col.ind = "black",
pallette = "jco",
label = "var",
col.var = "black",
repel = TRUE,
legend.title = "Age") +
ggtitle("Proteome Data and Age Correlation") + theme(plot.title = element_text(hjust = 0.5))
但是一个简单的例子可能会很有帮助。
我正在尝试根据数据在此处绘制主成分分析的结果,并将年龄作为颜色编码因素绘制到图上(如 link 中所附图片所示)
我想通过分组年龄范围而不是连续的颜色范围来改善视觉效果。例如,我想要三种颜色 group1 为 0-25 岁,group2 为 26 至 50 岁,group3 为 51+。有没有办法可以操纵这段代码来做到这一点?我试着在网上寻找这个,但我仍然不确定如何为这个代码集做这个。
# Plot the PCA with color coding of age
fviz_pca_ind(proteome_pr, geom.ind = "point", pointshape = 21,
pointsize = 2,
fill.ind = prot_subjectID$Age,
col.ind = "black",
pallette = "jco",
label = "var",
col.var = "black",
repel = TRUE,
legend.title = "Age") +
ggtitle("Proteome Data and Age Correlation") + theme(plot.title = element_text(hjust = 0.5))
Image of the generated figure
根据@MrFlick 的建议,您可以使用以下代码:
fviz_pca_ind(proteome_pr, geom.ind = "point", pointshape = 21,
pointsize = 2,
fill.ind = cut(prot_subjectID$Age, breaks = 10), # Here you can create groups.
col.ind = "black",
pallette = "jco",
label = "var",
col.var = "black",
repel = TRUE,
legend.title = "Age") +
ggtitle("Proteome Data and Age Correlation") + theme(plot.title = element_text(hjust = 0.5))
但是一个简单的例子可能会很有帮助。