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

info<-read_xlsx('datafig2ab.xlsx')
setDT(info)
unique(info[,.(choicere,p)])


dat<-info[,.(p=unique(p),
             transmitpercent=mean(transmitpercent,na.rm=T)),.(choicere)]
			 
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

				   
left<-c('D','C')
right<-c('B','A')

				   
showtext_auto()
font_add('sung','simsun.ttc')

   
tu.left<-ggplot(dat[group %in% left],aes(x=p,y=transmitpercent,group=group,colour=group))+
   geom_line()+
   geom_point(aes(shape=group))+
   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=10,family='sung',color='black'))+
   scale_colour_manual(name='',values=c('D'='#8b8b8b','C'='#4c4c4c'),breaks=c('D','C'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡'))+
   scale_shape_manual(name='',values=c('D'=0,'C'=1),breaks=c('D','C'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡'))
   
tu.right<-ggplot(dat[group %in% right],aes(x=p,y=transmitpercent,group=group,colour=group))+
   geom_line()+
   geom_point(aes(shape=group))+
   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=10,family='sung',color='black'))+
   scale_colour_manual(name='',values=c('A'='#8b8b8b','B'='#4c4c4c'),breaks=c('A','B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡'))+
   scale_shape_manual(name='',values=c('A'=0,'B'=1),breaks=c('A','B'),labels=c('无个人—慈善组织权衡','含个人—慈善组织权衡'))
   

