You are on page 1of 3

1 R SCRIPT FOR CORELATION

2 d<-cor

3 head(d)

4 plot(d)

5 cor(d)

6 cor(d, method = "kendal")

7 cor(d, method = "spearman")

8 cor(d, method = "pearson")

9 cor.test(d$Sepal.Length, d$Sepal.Width)

10

11 cr<-cor(d)

12 library(corrplot)

13 corrplot(cr)

14 corrplot(cr, method="pie")

15 corrplot(cr, method="color")

16 corrplot(cr, method="number")

17 corrplot(cr, type="lower")

18 corrplot(cr, type="upper")

19

20 physical component analysis in r prcomp

21
22

23 # Installing and loading required packages

24 install.packages("factoextra")

25 install.packages("FactoMineR")

26 library(factoextra)

27 library(FactoMineR)

28

29 # Creating the data frame

30 data <- data.frame(

31 ph = c(6.8, 7.2, 7.5, 7, 6.9, 7.3, 7.1),

32 EC = c(0.533333333, 1.5, 2, 1, 0.8, 1.8, 1.3),

33 OC = c(1.8, 1.5, 1.3, 2, 2.2, 1.9, 2.1),

34 Ex_Na = c(5, 10, 15, 8, 7, 12, 9),

35 N = c(180, 165, 150, 175, 180, 160, 170),

36 P = c(25, 20, 18, 23, 24, 20, 22),

37 K = c(200, 185, 170, 195, 200, 185, 195),

38 P = c(200, 185, 170, 195, 200, 185, 195),

39 MBC = c(400, 318.3333333, 280, 373.3333333, 390, 338.3333333, 360),

40 MBN = c(40, 30, 25, 37, 38, 33, 35)

41 )

42
43 # Performing PCA

44 res.pca <- PCA(data, scale.unit=TRUE, ncp=5, graph=FALSE)

45

46 # Visualizing the PCA results for variables

47 fviz_pca_var(res.pca,

48 col.var = "contrib", # Color by contributions to the PC

49 gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),

50 repel = TRUE # Avoid text overlapping

51 )

52 https://env.nankai.edu.cn/2019/0612/c14180a177263/page.htm

You might also like