### LQ Human Robot Integration ### # Clean space remove(list=ls()) dev.off() cat("\014") # Load Packages library(tidyverse) library(ggplot2) library(dplyr) library(ggpubr) library(gridExtra) library(grid) library(lattice) library(gtable) #### IMPORT DATA #### df<-readxl::read_excel("~/Desktop/R Practice /Leadership & Robotics Coding_Compiled.xlsx") #### SUBSET DATA - ONLY PHYSICAL ROBOT PUBLICATIONS #### mydata <-df[ which(df$`Physical Robot`==1), ] ############################## #### RENAME COLUMN VALUES #### ############################## # TaskOrRel mydata$TaskOrRel[mydata$TaskOrRel==1] <- "Task" mydata$TaskOrRel[mydata$TaskOrRel==2] <- "Relationship" mydata$TaskOrRel[mydata$TaskOrRel==3] <- "Both" mydata$TaskOrRel[mydata$TaskOrRel==4] <- "Other" # Area mydata$Area[mydata$Area==1] <- "Psychology" mydata$Area[mydata$Area==2] <- "Engineering" mydata$Area[mydata$Area==3] <- "Management" mydata$Area[mydata$Area==4] <- "Econ" # ConOrEmp mydata$ConOrEmp[mydata$ConOrEmp==1] <- "Conceptual" mydata$ConOrEmp[mydata$ConOrEmp==2] <- "Emperical" # Type mydata$Type[mydata$Type==1] <- "Book" mydata$Type[mydata$Type==2] <- "Conference" mydata$Type[mydata$Type==3] <- "Journal" mydata$Type[mydata$Type==4] <- "Other" # Robot Position mydata$`Robot Position`[mydata$`Robot Position`==1] <- "Follower" mydata$`Robot Position`[mydata$`Robot Position`==2] <- "Dyadic Partner" mydata$`Robot Position`[mydata$`Robot Position`==3] <- "Leader" mydata$`Robot Position`[mydata$`Robot Position`==4] <- "Follower" #Team member in coding mydata$`Robot Position`[mydata$`Robot Position`==5] <- "Other" mydata$`Robot Position`[mydata$`Robot Position`=="Multi"] <- "Other" # Robot Position mydata$Level[mydata$Level=="I"] <- "Individual" mydata$Level[mydata$Level=="D"] <- "Dyadic" mydata$Level[mydata$Level=="G"] <- "Group" mydata$Level[mydata$Level=="O"] <- "Organization" mydata$Level[mydata$Level=="Multi"] <- "Multilevel" #### Subset by Specific Area #### mngt <- mydata[ which(mydata$Area == "Management"), ] psy <- mydata[ which(mydata$Area == "Psychology"), ] eng <- mydata[ which(mydata$Area == "Engineering"), ] econ <- mydata[ which(mydata$Area == "Econ"), ] #### CREATE TABLE 4 IN MANUSCRIPT #### # Management pos_mngt<-as.data.frame(table(mngt$`Robot Position`)) dplyr::glimpse(pos_mngt) pos_mngt<-pos_mngt %>% arrange(match(Var1,c("Follower", "Dyadic Partner", "Leader","Other")), desc(Var1), desc(Freq)) pos_mngt # Economics pos_econ<-as.data.frame(table(econ$`Robot Position`)) dplyr::glimpse(pos_econ) pos_econ<-pos_econ %>% arrange(match(Var1,c("Follower", "Dyadic Partner", "Leader","Other")), desc(Var1), desc(Freq)) pos_econ # Psychology pos_psy<-as.data.frame(table(psy$`Robot Position`)) dplyr::glimpse(pos_psy) pos_psy<-pos_psy %>% arrange(match(Var1,c("Follower", "Dyadic Partner", "Leader","Other")), desc(Var1), desc(Freq)) pos_psy # Engineering pos_eng<-as.data.frame(table(eng$`Robot Position`)) dplyr::glimpse(pos_eng) pos_eng<-pos_eng %>% arrange(match(Var1,c("Follower", "Dyadic Partner", "Leader","Other")), desc(Var1), desc(Freq)) pos_eng ########################################### #### SUBSET DATA TO CREATE FIGURES 2-4 #### ########################################### ### Area Subsets psych <-mydata[ which(mydata$Area=="Psychology"), ] eng <-mydata[ which(mydata$Area=="Engineering"), ] mngt <-mydata[ which(mydata$Area=="Management"), ] econ <-mydata[ which(mydata$Area=="Econ"), ] ### ConOrEmp Subsets con <-mydata[ which(mydata$ConOrEmp=="Conceptual"), ] emp <-mydata[ which(mydata$ConOrEmp=="Emperical"), ] ### Task or Relation Subsets task <-mydata[ which(mydata$TaskOrRel=="Task"), ] relation <-mydata[ which(mydata$TaskOrRel=="Relation"), ] both <-mydata[ which(mydata$TaskOrRel=="Both"), ] other <-mydata[ which(mydata$TaskOrRel=="Other"), ] ### Level Subsets I <-mydata[ which(mydata$Level=="Individual"), ] D <-mydata[ which(mydata$Level=="Dyadic"), ] G <-mydata[ which(mydata$Level=="Group"), ] O <-mydata[ which(mydata$Level=="Organization"), ] Multi <-mydata[ which(mydata$Level=="Multilevel"), ] ####################################### #### CREATE FIGURES FOR MANUSCRIPT #### ####################################### #### FIGURE 2 IN MANUSCRIPT #### # Subset Data Task <-mydata[ which(mydata$`TaskOrRel`=="Task"), ] Relation<-mydata[ which(mydata$`TaskOrRel`=="Relationship"), ] Both <-mydata[ which(mydata$`TaskOrRel`=="Both"), ] # Create Invidual Histograms for Each Subset plot1 <- qplot(Task$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("lightblue"),col=I("blue"),ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Task-based") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) plot2 <- qplot(Relation$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("pink"),col=I("red"),ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Relationship-based") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) plot3 <- qplot(Both$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("lemon chiffon"),col=I("orange"),ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Both Task-based and Relationship-based") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) # Combine Histograms into One Plot Figure2 <- ggarrange(plot1, plot2, plot3, ncol=1, nrow=3) # Save the Figure 2 Plot by file type (png, pdf, jpeg, tiff, etc.) ggsave(Figure2, filename = "~/Desktop/Figure2.png", units="in", width=3, height=5) #### FIGURE 3 IN MANUSCRIPT #### # Create Position Subsets Follower <-mydata[ which(mydata$`Robot Position`=="Follower"), ] DyadPartner <-mydata[ which(mydata$`Robot Position`=="Dyadic Partner"), ] Leader <-mydata[ which(mydata$`Robot Position`=="Leader"), ] Other <-mydata[ which(mydata$`Robot Position`=="Other"), ] # Create Histograms by Position plot1 <- qplot(Follower$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("lightblue"),col=I("blue"),ylim=c(0,15),xlim=c(1980,2020)) + ggtitle("Robots as Followers") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) plot2 <- qplot(DyadPartner$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("pink"),col=I("red"),ylim=c(0,15),xlim=c(1980,2020)) + ggtitle("Robots as Dyadic Partners") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) plot3 <- qplot(Leader$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("lemon chiffon"),col=I("orange"),ylim=c(0,15),xlim=c(1980,2020)) + ggtitle("Robots as Leaders") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) plot4 <- qplot(Other$Year, breaks=seq(1980,2021,by=2),geom="histogram",fill=I("grey"),col=I("black"),ylim=c(0,15),xlim=c(1980,2020)) + ggtitle("Robots as Other") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=7, family="serif")) # Plot All Histograms in One Plot Figure3 <- ggarrange(plot1, plot2, plot3, ncol=1, nrow=3) # Save the Figure 3 Plot by file type (png, pdf, jpeg, tiff, etc.) ggsave(Figure3, filename = "~/Desktop/Figure3.png", units="in", width=3, height=5) #### FIGURE 4 IN MANUSCRIPT #### ### Histograms by Level plot1 <- qplot(I$Year, breaks=seq(1963,2020,by=2),geom="histogram",fill=I("lightblue"),col=I("blue")) + coord_cartesian(ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Individual level") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=10, family="serif")) plot2 <- qplot(D$Year, breaks=seq(1963,2020,by=2),geom="histogram",fill=I("pink"),col=I("red")) + coord_cartesian(ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Dyad level") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=10, family="serif")) plot3 <- qplot(G$Year, breaks=seq(1963,2020,by=2),geom="histogram",fill=I("lemon chiffon"),col=I("orange")) + coord_cartesian(ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Group level") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=10, family="serif")) plot4 <- qplot(O$Year, breaks=seq(1963,2020,by=2),geom="histogram",fill=I("lightgreen"),col=I("green")) + coord_cartesian(ylim=c(0,20),xlim=c(1980,2020)) + ggtitle("Organization level") + xlab("Year") + ylab("Number")+ theme(text=element_text(size=10, family="serif")) # Plot All Histograms in One in 2 x 2 Display for I,D,G,O Plot Figure4 <- ggarrange(plot1, plot2, plot3, plot4, ncol=2, nrow=2) # Save the Figure 4 Plot by file type (png, pdf, jpeg, tiff, etc.) ggsave(Figure4, filename = "~/Desktop/Figure4.png", units="in", width=7, height=5) #### OTHER TABLES NOT USED IN MANUSCRIPT #### # Area A<-as.data.frame(table(mydata$Area)) dplyr::glimpse(A) A<-A %>% arrange(match(Var1,c("Psychology", "Engineering", "Management","Econ")), desc(Var1), desc(Freq)) A # Area JBC<-as.data.frame(table(mydata$Type)) dplyr::glimpse(JBC) JBC<-JBC %>% arrange(match(Var1,c("Journal", "Book", "Conference","Other")), desc(Var1), desc(Freq)) JBC # Robot Position R<-as.data.frame(table(mydata$`Robot Position`)) dplyr::glimpse(R) R<-R %>% arrange(match(Var1,c("Follower", "Dyadic Partner", "Leader","Other")), desc(Var1), desc(Freq)) R # TaskOrRel T<-as.data.frame(table(mydata$TaskOrRel)) dplyr::glimpse(T) T<-T %>% arrange(match(Var1,c("Task", "Relation", "Both","Other")), desc(Var1), desc(Freq)) T # Level L<-as.data.frame(table(mydata$Level)) dplyr::glimpse(L) L<-L %>% arrange(match(Var1,c("I", "D", "G","O","Multi","Industry")), desc(Var1), desc(Freq)) L # ConOrEmp C<-as.data.frame(table(mydata$ConOrEmp)) dplyr::glimpse(C) C<-C %>% arrange(match(Var1,c("Conceptual", "Emperical")), desc(Var1), desc(Freq)) C