library(reshape2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
#install.packages("ggsci")
library(ggsci)
library(readxl)
zqp <- read_excel("E:/copaer/zqp.xlsx")
zqp1<-melt(zqp,id.vars=c("year")) #变成一个长数据 
View(zqp1)
names(zqp)
## [1] "year"            "individual_love" "relational_love" "collective_love"
## [5] "anger"           "death"           "anxiety"         "depression"
bks <- c(1960, 1970,1980,1990,2000, 2010,2020)
ggplot(zqp)+
  geom_point(aes(x=year,y=individual_love))+
  geom_line(aes(x=year,y=individual_love))+ scale_x_continuous(breaks = bks)

ggsave("individual_love.png", width=6, height=6, dpi=3000)
ggplot(zqp)+
  geom_point(aes(x=year,y=relational_love))+
  geom_line(aes(x=year,y=relational_love))+ scale_x_continuous(breaks = bks)

ggsave("relational_love.png", width=6, height=6, dpi=3000)
ggplot(zqp)+
  geom_point(aes(x=year,y=collective_love))+
  geom_line(aes(x=year,y=collective_love))+ scale_x_continuous(breaks = bks)

ggsave("collective_love.png", width=6, height=6, dpi=3000)

names(zqp1)
## [1] "year"     "variable" "value"
zqp1 %>% 
  filter(variable%in%c('individual_love','relational_love','collective_love'))%>% 
  ggplot(aes(x=year,y=value,color=variable,shape=variable))+
  geom_line()+ geom_point()+
  scale_x_continuous(breaks = bks)

ggsave("all.png", width=8, height=6, dpi=3000)  
zqp1 %>% 
  filter(variable%in%c('individual_love','relational_love','collective_love'))%>% 
  ggplot(aes(x=year,y=value,color=variable,shape=variable))+
  geom_line()+ geom_point()+
  scale_x_continuous(breaks = bks)+
  theme_bw() + scale_color_aaas()

ggsave("all2.png", width=8, height=6, dpi=3000)  
zqp1 %>% 
  filter(variable%in%c('individual_love','relational_love','collective_love'))%>% 
  ggplot(aes(x=year,y=value,color=variable,shape=variable))+
  geom_line()+ geom_point()+
  scale_x_continuous(breaks = bks)+
   scale_colour_grey(end =1)

ggsave("allblack.png", width=8, height=6, dpi=3000)  

#install.packages('see')
#install.packages("report")

library(correlation)
## Registered S3 methods overwritten by 'parameters':
##   method                           from      
##   as.double.parameters_kurtosis    datawizard
##   as.double.parameters_skewness    datawizard
##   as.double.parameters_smoothness  datawizard
##   as.numeric.parameters_kurtosis   datawizard
##   as.numeric.parameters_skewness   datawizard
##   as.numeric.parameters_smoothness datawizard
##   print.parameters_distribution    datawizard
##   print.parameters_kurtosis        datawizard
##   print.parameters_skewness        datawizard
##   summary.parameters_kurtosis      datawizard
##   summary.parameters_skewness      datawizard
library(report)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(dplyr)
#library(see)
cor<-zqp %>%
  select(2:8) %>%
  correlation()

zqp %>%
  select(2:8) %>%
  correlation() %>%
  summary()
## # Correlation Matrix (pearson-method)
## 
## Parameter       | depression |  anxiety |   death |    anger | collective_love | relational_love
## ------------------------------------------------------------------------------------------------
## individual_love |    0.65*** |  0.77*** | 0.58*** | -0.52*** |        -0.65*** |         0.98***
## relational_love |    0.74*** |  0.73*** | 0.67*** |  -0.42** |        -0.57*** |                
## collective_love |      -0.04 | -0.76*** |   -0.14 |  0.84*** |                 |                
## anger           |       0.23 | -0.55*** |    0.28 |          |                 |                
## death           |    0.88*** |   0.43** |         |          |                 |                
## anxiety         |       0.28 |          |         |          |                 |                
## 
## p-value adjustment method: Holm (1979)
zqp %>%
  select(2:8) %>%
  correlation()
## # Correlation Matrix (pearson-method)
## 
## Parameter1      |      Parameter2 |     r |         95% CI | t(57) |         p
## ------------------------------------------------------------------------------
## individual_love | relational_love |  0.98 | [ 0.97,  0.99] | 38.12 | < .001***
## individual_love | collective_love | -0.65 | [-0.78, -0.47] | -6.42 | < .001***
## individual_love |           anger | -0.52 | [-0.69, -0.31] | -4.66 | < .001***
## individual_love |           death |  0.58 | [ 0.39,  0.73] |  5.44 | < .001***
## individual_love |         anxiety |  0.77 | [ 0.64,  0.86] |  9.19 | < .001***
## individual_love |      depression |  0.65 | [ 0.48,  0.78] |  6.52 | < .001***
## relational_love | collective_love | -0.57 | [-0.72, -0.37] | -5.27 | < .001***
## relational_love |           anger | -0.42 | [-0.61, -0.18] | -3.48 | 0.006**  
## relational_love |           death |  0.67 | [ 0.50,  0.79] |  6.81 | < .001***
## relational_love |         anxiety |  0.73 | [ 0.59,  0.83] |  8.17 | < .001***
## relational_love |      depression |  0.74 | [ 0.60,  0.84] |  8.33 | < .001***
## collective_love |           anger |  0.84 | [ 0.74,  0.90] | 11.52 | < .001***
## collective_love |           death | -0.14 | [-0.38,  0.12] | -1.08 | 0.571    
## collective_love |         anxiety | -0.76 | [-0.85, -0.63] | -8.95 | < .001***
## collective_love |      depression | -0.04 | [-0.29,  0.22] | -0.29 | 0.773    
## anger           |           death |  0.28 | [ 0.02,  0.50] |  2.18 | 0.166    
## anger           |         anxiety | -0.55 | [-0.71, -0.34] | -4.97 | < .001***
## anger           |      depression |  0.23 | [-0.03,  0.46] |  1.79 | 0.239    
## death           |         anxiety |  0.43 | [ 0.20,  0.62] |  3.62 | 0.004**  
## death           |      depression |  0.88 | [ 0.80,  0.92] | 13.67 | < .001***
## anxiety         |      depression |  0.28 | [ 0.02,  0.50] |  2.18 | 0.166    
## 
## p-value adjustment method: Holm (1979)
## Observations: 59
cors<-zqp %>%
  select(2:8) %>%
  correlation() %>%
  summary()
write.csv(cor,'cor.csv')
write.csv(cors,'cors.csv')
zqp %>%
  select(2:8) %>%
  correlation()%>%plot()
## NULL
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
zqp %>%
  select(2:8) %>%
  ggpairs()

library(corrplot)  
## corrplot 0.90 loaded
cordat<-zqp %>%
  select(2:8)
M = cor(cordat) #计算系数矩阵
testRes = cor.mtest(cordat, conf.level = 0.95) #计算显著性
corrplot(M, p.mat = testRes$p, method = 'circle', type = 'lower', insig='blank',
         addCoef.col ='black', number.cex = 0.8, order = 'AOE', diag=FALSE)

#ggsave("cor.png", width=8, height=6, dpi=3000)  
corrplot(M)