在R图中匹配点和图例时出错

时间:2015-05-04 02:59:28

标签: r graphics plot ggplot2 scatter-plot

我想在R中制作一个情节。但是,我无法匹配传奇和积分。我的代码是:

G is a matrix and I want the color and simbols (pch) based on the G row names.


pdf(file = "PCA.pdf", width = 8, height = 8)
plot(pca$x[,2], pca$x[,1], 
main="Principal components", xlab="First principal component", ylab="Second principal component",
col= ifelse(row.names(G) == "RL", "black", ifelse(row.names(G) == "BOAUS", "red", 
ifelse(row.names(G) == "BOCAN", "pink",
ifelse(row.names(G) == "AL", "green",
ifelse(row.names(G) == "EN", "blue",
ifelse(row.names(G) == "LN", "yellow",
ifelse(row.names(G) == "TO", "orange",
ifelse(row.names(G) == "NU", "purple",
ifelse(row.names(G) == "CA", "grey", "white"))))))))), pch= ifelse(row.names(G) == "RL", 1, ifelse(row.names(G) == "BOAUS", 2, 
ifelse(row.names(G) == "BOCAN", 3,
ifelse(row.names(G) == "AL", 4,
ifelse(row.names(G) == "EN", 5,
ifelse(row.names(G) == "LN", 6,
ifelse(row.names(G) == "TO", 7,
ifelse(row.names(G) == "NU", 8,
ifelse(row.names(G) == "CA", 9, 10))))))))))

legend("bottomright", unique(rownames(G)), col= ifelse(row.names(G) == "RL", "black", ifelse(row.names(G) == "BOAUS", "red", 
ifelse(row.names(G) == "BOCAN", "pink",
ifelse(row.names(G) == "AL", "green",
ifelse(row.names(G) == "EN", "blue",
ifelse(row.names(G) == "LN", "yellow",
ifelse(row.names(G) == "TO", "orange",
ifelse(row.names(G) == "NU", "purple",
ifelse(row.names(G) == "CA", "grey", "white"))))))))), pch= ifelse(row.names(G) == "RL", 1, ifelse(row.names(G) == "BOAUS", 2, 
ifelse(row.names(G) == "BOCAN", 3,
ifelse(row.names(G) == "AL", 4,
ifelse(row.names(G) == "EN", 5,
ifelse(row.names(G) == "LN", 6,
ifelse(row.names(G) == "TO", 7,
ifelse(row.names(G) == "NU", 8,
ifelse(row.names(G) == "CA", 9, 10))))))))), ncol=3, cex=0.7)
dev.off()

我得到的情节是: 任何有关如何获得更好的情节的帮助将非常感激。感谢。

0 个答案:

没有答案