Sunday, November 20, 2016

Check Bivariate Distribution in R

data$index=1+(data$rankP-mean(data$rankP))/sd(data$rankP)
ggplot(data, aes(y=data$index, x=data$Avg...Viewed)) +
  geom_density_2d() +
  ggtitle("Contour Plot of Original APV and APV Index") +
  ylab("Original APV Index") +
  xlab("Origianl APV") +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90))

## Type
p1=ggplot(data, aes(y=data$Avg...Viewed, x=data$Type)) +
  geom_boxplot(aes(fill = data$Type), outlier.colour = "red", outlier.size = 2) +
  ggtitle("Boxplot of Original APV by Type") +
  ylab("Original APV") +
  xlab("Type") +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90)) +
  guides(fill=FALSE)
p2=ggplot(data, aes(y=data$index, x=data$Type)) +
  geom_boxplot(aes(fill = data$Type), outlier.colour = "red", outlier.size = 2) +
  ggtitle("Boxplot of APV Index by Type") +
  ylab("APV Index") +
  xlab("Type") +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90)) +
  guides(fill=FALSE)

#X..Eps
p3=ggplot(data, aes(y=data$Avg...Viewed, x=data$X..Eps)) +
  geom_density_2d() +
  ggtitle("Contor Plot of Original APV by Number of Episodes") +
  ylab("Original APV") +
  xlab("Number of Episodes") +
  scale_x_continuous(limits=c(0,25)) +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90))
p4=ggplot(data, aes(y=data$index, x=data$X..Eps)) +
  geom_density_2d() +
  ggtitle("Contor Plot of APV Index by Number of Episodes") +
  ylab("APV Index") +
  xlab("Number of Episodes") +
  scale_x_continuous(limits=c(0,30)) +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90))

## daypart
p5=ggplot(data, aes(y=data$Avg...Viewed, x=data$daypart)) +
  geom_boxplot(aes(fill = data$daypart), outlier.colour = "red", outlier.size = 2) +
  ggtitle("Boxplot of Original APV by Daypart") +
  ylab("Original APV") +
  xlab("Daypart") +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90)) +
  guides(fill=FALSE)
p6=ggplot(data, aes(y=data$index, x=data$daypart)) +
  geom_boxplot(aes(fill = data$daypart), outlier.colour = "red", outlier.size = 2) +
  ggtitle("Boxplot of APV Index by Type") +
  ylab("APV Index") +
  xlab("Daypart") +
  theme(plot.title = element_text(face = "bold", size = 20)) +
  theme(axis.text.x = element_text(face = "bold", size = 14)) +
  theme(axis.text.y = element_text(face = "bold", size = 14)) +
  theme(axis.title.x = element_text(face = "bold", size = 16)) +
  theme(strip.text.x = element_text(face = "bold", size = 16)) +
  theme(axis.title.y = element_text(face = "bold", size = 16, angle=90)) +
  guides(fill=FALSE)

pdf("result.pdf", width=15, height=8.5)
grid.arrange(p1,p2, ncol=2)
grid.arrange(p3,p4, ncol=2)
grid.arrange(p5,p6, ncol=2)
dev.off()

No comments:

Post a Comment

Blog Archive