Hello, I would like to create a plot composed of stacked boxes (squares or rectangles), where the size of the box would represent the frequency of observations based on a categorical variable (group), the color would represent the proportion of success (binary) within that group (outcome) on a predetermined color scale. Ideally the boxes can be stacked from the bottom left to the top right based on size. The x and y scales are not informative. I am experimenting with the rect() function and loops but I wasn't able to generate an appealing graph. Thanks Osman Here is simulated data set group<-rep(c('a','b','c','d','e','f','g'),c(100,20,300,40,2,10,40)) outcome<-c(sample(c(0,1),100,rep=T,p=c(0.98,0.02)), sample(c(0,1),20,rep=T,p=c(0.9,0.1)), sample(c(0,1),300,rep=T,p=c(0.99,0.01)), sample(c(0,1),40,rep=T,p=c(0.95,0.05)), sample(c(0,1),2,rep=T,p=c(0.5,0.5)), sample(c(0,1),10,rep=T,p=c(0.9,0.1)), sample(c(0,1),40,rep=T,p=c(0.8,0.2))) df<-data.frame(group=group,outcome=as.numeric(outcome)) Osman O. Al-Radi, MD, MSc, FRCSC Staff Cardiovascular Surgeon Co-medical director, Tissue Bank The Hospital for Sick Children University of Toronto, Canada [[alternative HTML version deleted]]
Hello, I would like to create a plot composed of stacked boxes (squares or rectangles), where the size of the box would represent the frequency of observations based on a categorical variable (group), the color would represent the proportion of success (binary) within that group (outcome) on a predetermined color scale. Ideally the boxes can be stacked from the bottom left to the top right based on size. The x and y scales are not informative. I am experimenting with the rect() function and loops but I wasn't able to generate an appealing graph. Thanks Osman Here is simulated data set group<-rep(c('a','b','c','d','e','f','g'),c(100,20,300,40,2,10,40)) outcome<-c(sample(c(0,1),100,rep=T,p=c(0.98,0.02)), sample(c(0,1),20,rep=T,p=c(0.9,0.1)), sample(c(0,1),300,rep=T,p=c(0.99,0.01)), sample(c(0,1),40,rep=T,p=c(0.95,0.05)), sample(c(0,1),2,rep=T,p=c(0.5,0.5)), sample(c(0,1),10,rep=T,p=c(0.9,0.1)), sample(c(0,1),40,rep=T,p=c(0.8,0.2))) df<-data.frame(group=group,outcome=as.numeric(outcome)) Osman O. Al-Radi, MD, MSc, FRCSC Staff Cardiovascular Surgeon Co-medical director, Tissue Bank The Hospital for Sick Children University of Toronto, Canada [[alternative HTML version deleted]]