xxxxxxxxxx
print(r.eval("""
library(tidyverse)
user<-'https://raw.githubusercontent.com/osanchez2323/Portfolio/master/'
folder1<-paste0(user,'Data%20Science%20Takes%20on%20Education/Data/')
file1<-paste0(folder1,'2016%20School%20Explorer.csv')
file2<-paste0(folder1,'D5%20SHSAT%20Registrations%20and%20Testers.csv')
se<-read.csv(file1); d5<-read.csv(file2)
se<-se[,4:161]; se[se=='N/A']<-NA
cat(c(paste0('se => ',list(dim(se))),
paste0('d5 => ',list(dim(d5)))),'\n')
se$School.Name<-as.character(se$School.Name)
se$School.Name[428]<-'P.S. 212 D12'
se$School.Name[1024]<-'P.S. 212 D30'
se$School.Name[713]<-'P.S. 253 D21'
se$School.Name[909]<-'P.S. 253 D27'
percent_list<-
c('Percent.ELL','Percent.Asian','Percent.Black',
'Percent.Hispanic','Percent.Black...Hispanic','Percent.White',
'Student.Attendance.Rate','Percent.of.Students.Chronically.Absent',
'Rigorous.Instruction..','Collaborative.Teachers..',
'Supportive.Environment..','Effective.School.Leadership..',
'Strong.Family.Community.Ties..','Trust..')
target_list<-c('Average.ELA.Proficiency','Average.Math.Proficiency')
economic_list<-c('Economic.Need.Index','School.Income.Estimate')
rating_list<-
c('Rigorous.Instruction.Rating','Collaborative.Teachers.Rating',
'Supportive.Environment.Rating','Effective.School.Leadership.Rating',
'Strong.Family.Community.Ties.Rating','Trust.Rating',
'Student.Achievement.Rating')
str2num<-function(x){
x<-as.character(x)
for (s in c('%','$',',')){x<-sub(s,'',x)}
x<-as.numeric(x)}
for (el in c(percent_list,target_list,economic_list)) {
se[el]<-sapply(se[el],str2num)
se<-se%>%dplyr::group_by(City)%>%
fill(all_of(el),.direction='downup')%>%dplyr::ungroup()}
for (el in rating_list){
vtable<-data.frame(table(se[el]))
mvalue<-as.character(vtable$Var1[vtable$Freq==max(vtable$Freq)])
se[el][is.na(se[el])]<-mvalue}
sum(is.na(se))
"""))
xxxxxxxxxx
print(r.eval("""
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
theme_set(theme_bw())
cols<-c('#3300ff','#ff0033','#9f9fff','#ff9f9f')
vc=c(cols[4],cols[1],cols[3],cols[2])
vtable<-data.frame(table(se[rating_list[1]]))[c(1,2,3,5),1:2]
p<-ggplot(vtable,aes(x=factor(1),y=Freq,fill=factor(Var1)))+
geom_bar(width=1,stat='identity')+
coord_polar(theta='y')+
scale_fill_manual(name=gsub('.',' ',rating_list[1]),values=vc)+
theme(axis.title=element_blank(),axis.line=element_blank(),
axis.ticks.y=element_blank(),axis.text.y=element_blank(),
axis.text.x=element_text(colour=cols[2],size=4,angle=60),
legend.text=element_text(size=3),
legend.key.size=unit(.3,'cm'),
legend.key=element_rect(color='slategray'),
title=element_text(size=4,hjust=.5),
panel.background=element_rect(fill='slategray'))
ggsave(fn,width=2.1,height=1.5)
dev.off()
"""))