我创建了以下得分图,但问题是图例没有正确的颜色。我的数据有7个类别,我根据这7个类别分配颜色来绘制。但是,我无法为图例指定正确的关联颜色代码。我怎么能这样做?
这是我的简短剧本:
install.packages("pls")
library("pls")
data_PCA<-data[,c(-1,-2,-4,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-20,-21,-22,-25,-26)]
data.scale<-scale(data_PCA)
pca<-prcomp(data.scale)
scoreplot(pca,col=data$Core_Lithofacies_No,pch=16,
ylab="Second Component (24%)",xlab="First Component (54%)")
abline(0,0)
abline(v=0)
legend(1,7,c("Lithofacies 1", "Lithofacies 2","Lithofacies 3",
"Lithofacies 4", "Lithofacies 5","Lithofacies 6","Lithoacies 7"),
pch=16,
col = data$Core_Lithofacies_No)
这是我的数据
DEPTH CAL DPHI DRHO DTC GR NPHI P10AF P1AF P2AF P3AF P4AF P5AF P6AF P7AF P8AF P9AF PE RHOB RT10 RT20 RT60 RT90 SP Core_Lithofacies_No Core_Lithofacies_Name
4789 8.843 0.048 0.011 59.592 54.151 0.115 0 1.166 0.604 1.202 1.879 0.508 1.248 0.451 0.005 0 2.59 2.628 6.524 10.098 5.396 5.311 -36.244 2 Skeletal packstone-grainstone
4789.5 8.844 0.018 0.019 56.809 40.889 0.069 0.001 1.466 0.476 0.949 1.546 0.263 1.178 0.524 0.001 0 2.937 2.679 8.289 11.67 6.45 6.33 -36.257 2 Skeletal packstone-grainstone
4790 8.834 0.005 0.025 54.694 28.069 0.061 0.025 1.21 0.233 0.906 1.229 0.151 1.008 0.58 0.014 0.009 3.744 2.701 11.761 14.685 8.242 8.041 -36.582 2 Skeletal packstone-grainstone
4790.5 8.852 0.009 0.019 52.615 21.113 0.064 0.085 0.501 0.15 0.961 0.893 0.307 0.696 0.417 0.08 0.077 4.645 2.695 13.937 18.858 9.176 8.912 -38.101 2 Skeletal packstone-grainstone
4791 8.855 0.024 0.01 51.77 23.401 0.074 0.078 0.056 0.228 1.013 0.548 0.464 0.435 0.26 0.185 0.171 5.047 2.669 18.325 22.075 10.868 10.47 -39.779 2 Skeletal packstone-grainstone
4791.5 8.858 0.037 0.004 52.798 30.77 0.082 0.029 0.001 0.209 0.949 0.516 0.286 0.342 0.511 0.218 0.095 5.033 2.647 25.218 22.913 12.936 12.33 -41.234 2 Skeletal packstone-grainstone
4792 8.872 0.037 0.001 55.267 33.384 0.087 0.003 0.011 0.136 0.911 0.571 0.083 0.567 0.783 0.135 0.011 4.779 2.646 31.106 19.485 14.334 13.539 -41.324 2 Skeletal packstone-grainstone
4792.5 8.853 0.034 0.006 57.811 30.163 0.094 0 0.069 0.197 0.826 0.619 0.162 0.943 0.793 0.082 0.005 4.454 2.651 31.977 16.751 14.703 13.819 -40.371 2 Skeletal packstone-grainstone
4793 8.863 0.05 0.009 59.754 29.967 0.105 0.001 0.164 0.501 0.789 0.621 0.461 1.269 0.773 0.112 0.014 4.451 2.625 24.776 13.948 13.287 12.532 -39.243 2 Skeletal packstone-grainstone
4793.5 8.857 0.089 0.007 60.145 37.838 0.12 0 0.664 0.772 0.49 0.851 0.713 1.404 1.001 0.084 0.006 4.611 2.557 20.085 10.323 12.066 11.428 -40.33 1 Brecciated chert
4794 8.845 0.113 0.001 60.206 46.126 0.141 0.001 1.432 0.709 0.161 0.935 1.101 1.508 1.171 0.069 0.007 4.246 2.517 16.308 8.911 10.627 10.128 -42.135 1 Brecciated chert
4794.5 8.844 0.117 -0.008 60.333 46.082 0.16 0.036 1.464 0.608 0.299 0.596 1.416 2.015 0.978 0.081 0.086 3.412 2.511 11.728 9.248 8.437 8.125 -42.395 1 Brecciated chert
4795 8.833 0.146 0.004 58.667 39.132 0.146 0.192 0.813 0.608 0.838 0.366 1.422 2.585 0.679 0.062 0.228 3.093 2.46 9.956 10.082 7.529 7.291 -42.588 1 Brecciated chert
4795.5 8.818 0.182 0.024 56.208 31.132 0.124 0.297 0.428 0.637 1.112 0.341 1.433 2.715 0.618 0.073 0.305 3.353 2.399 10.257 10.395 7.855 7.613 -43.838 1 Brecciated chert
4796 8.808 0.159 0.023 54.036 24.604 0.098 0.301 0.096 0.54 1.089 0.455 1.692 2.56 0.69 0.21 0.461 3.372 2.439 11.093 11.45 8.564 8.303 -45.1 3 Peloidal mudstone-wackestone
4796.5 8.832 0.096 0.012 52.741 19.7 0.083 0.211 0.093 0.5 0.659 0.423 1.984 2.492 0.789 0.37 0.511 3.285 2.545 11.289 12.357 8.913 8.662 -46.069 3 Peloidal mudstone-wackestone
4797 8.84 0.05 0.003 52.552 17.243 0.075 0.089 0.232 0.587 0.323 0.408 1.978 2.307 1.076 0.602 0.321 3.688 2.624 12.393 12.829 9.817 9.554 -47.032 3 Peloidal mudstone-wackestone
4797.5 8.855 0.03 -0.006 52.842 16.399 0.075 0.01 0.39 0.619 0.104 0.466 1.875 1.789 1.423 0.776 0.104 4.379 2.66 13.401 12.725 10.618 10.355 -48.013 3 Peloidal mudstone-wackestone
4798 8.858 0.026 -0.008 52.994 15.637 0.073 0 0.507 0.456 0.027 0.319 1.783 1.51 1.41 0.772 0.053 4.815 2.665 13.962 13.193 11.097 10.857 -48.567 3 Peloidal mudstone-wackestone
4798.5 8.862 0.03 -0.005 53.507 15.846 0.074 0.012 0.519 0.275 0.101 0.289 1.25 1.558 1.271 0.658 0.066 4.965 2.658 13.837 13.948 11.132 10.933 -50.204 3 Peloidal mudstone-wackestone
4799 8.859 0.038 -0.006 54.531 17.943 0.075 0.087 0.228 0.236 0.387 0.392 0.544 1.544 1.299 0.387 0.068 5.052 2.645 14.364 13.965 11.594 11.418 -50.72 3 Peloidal mudstone-wackestone
4799.5 8.855 0.049 -0.006 55.355 19.327 0.083 0.126 0.035 0.144 0.567 0.441 0.324 1.395 1.304 0.185 0.035 5.088 2.626 15.241 14.391 12.263 12.107 -49.704 3 Peloidal mudstone-wackestone
4800 8.856 0.059 -0.005 55.549 17.593 0.081 0.059 0.048 0.091 0.43 0.348 0.617 1.452 0.96 0.214 0.076 5.019 2.609 15.242 14.761 12.336 12.213 -48.105 3 Peloidal mudstone-wackestone