library(readxl)
library(data.table)
library(ggplot2)
library(showtext)
library(patchwork)

info<-read_xlsx('datafig2cd.xlsx')
setDT(info)
unique(info[,.(choicere,p)])
info[,treatment:=as.character(treatment)]

dat<-info[,.(p=unique(p),
             transmitpercent=mean(transmitpercent,na.rm=T)),.(choicere,treatment)]
			 
dat[,group:=fcase(choicere %in% c(24:30),'A',
                  choicere %in% c(17:23),'B',
                  choicere %in% c(10:16),'C',
                  choicere %in% c(3:9),'D',
				  default='Other')]
				  
dat[,interG:=paste0(treatment,group)]

				   
left<-c('8B','8A','6B','7B')
right<-c('8B','8A','9B','10B')
				   
showtext_auto()
font_add('sung','simsun.ttc')

tu.left<-ggplot(dat[interG %in% left],aes(x=p,y=transmitpercent,group=interG,colour=interG))+
   geom_line()+
   geom_point(aes(shape=interG))+
   geom_line(aes(x=p,y=p),linetype=2,colour='black')+
   theme_bw()+
   coord_equal()+
   scale_x_continuous(limits=c(0,100),breaks=seq(0,100,by=10))+
   scale_y_continuous(limits=c(0,100),breaks=seq(0,100,by=10))+
   labs(x='慈善组织可获收益概率（P)',y='慈善组织风险收益估值')+
   #theme(axis.title=element_text(size=15,family='sung',color='black'))+
   #scale_colour_manual(name='',values=c('8A'='darkblue','8B'='darkred','7B'='darkgreen','6B'='orange'),breaks=c('8A','8B','7B','6B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉得分','含个人—慈善组织权衡：低声誉得分'))
   scale_colour_manual(name='',values=c('8A'='#8b8b8b','8B'='#4c4c4c','7B'='black','6B'='#A8A8A8'),breaks=c('8A','8B','7B','6B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉得分','含个人—慈善组织权衡：低声誉得分'))+
   scale_shape_manual(name='',values=c('8A'=0,'8B'=1,'7B'=2,'6B'=8),breaks=c('8A','8B','7B','6B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉得分','含个人—慈善组织权衡：低声誉得分'))
   
tu.right<-ggplot(dat[interG %in% right],aes(x=p,y=transmitpercent,group=interG,colour=interG))+
   geom_line()+
   geom_point(aes(shape=interG))+
   geom_line(aes(x=p,y=p),linetype=2,colour='black')+
   theme_bw()+
   coord_equal()+
   scale_x_continuous(limits=c(0,100),breaks=seq(0,100,by=10))+
   scale_y_continuous(limits=c(0,100),breaks=seq(0,100,by=10))+
   labs(x='慈善组织可获收益概率（P)',y='慈善组织风险收益估值')+
   #theme(axis.title=element_text(size=15,family='sung',color='black'))+
   #scale_colour_manual(name='',values=c('8A'='darkblue','8B'='darkred','10B'='darkgreen','9B'='orange'),breaks=c('8A','8B','10B','9B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉排名','含个人—慈善组织权衡：低声誉排名'))
   scale_colour_manual(name='',values=c('8A'='#8b8b8b','8B'='#4c4c4c','10B'='black','9B'='#A8A8A8'),breaks=c('8A','8B','10B','9B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉排名','含个人—慈善组织权衡：低声誉排名'))+
   scale_shape_manual(name='',values=c('8A'=0,'8B'=1,'10B'=2,'9B'=8),,breaks=c('8A','8B','10B','9B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡','含个人—慈善组织权衡：高声誉排名','含个人—慈善组织权衡：低声誉排名'))
 
