Bivariate Chart

Authors

[Editor] Hu Zheng;

[Contributors]

Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Bivariate Chart plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:

https://hiplot.cn/basic/bivariate?lang=en

Display the bivariate.

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: GGally

# Install packages
if (!requireNamespace("GGally", quietly = TRUE)) {
  install.packages("GGally")
}

# Load packages
library(GGally)

Data Preparation

# Load data
data <- read.table("files/Hiplot/014-bivariate-data.txt", header = T)

# View data
head(data)
  total_bill  tip gender smoker day   time size
1      16.99 1.01 Female     No Sun Dinner    2
2      10.34 1.66   Male     No Sun Dinner    3
3      21.01 3.50   Male     No Sun Dinner    3
4      23.68 3.31   Male     No Sun Dinner    2
5      24.59 3.61 Female     No Sun Dinner    4
6      25.29 4.71   Male     No Sun Dinner    4

Visualization

# Bivariate Chart
p <- ggbivariate(data, outcome = "smoker", 
                 explanatory = c("day","time","gender","tip")) +
  ggtitle("Bivariate") +
  scale_fill_manual(values = c("#e04d39","#5bbad6")) +
  theme_bw() +
  theme(text = element_text(family = "Arial"),
        plot.title = element_text(size = 12,hjust = 0.5),
        axis.title = element_text(size = 12),
        axis.text = element_text(size = 10),
        axis.text.x = element_text(angle = 0, hjust = 0.5),
        legend.position = "right",
        legend.direction = "vertical",
        legend.title = element_text(size = 10),
        legend.text = element_text(size = 10))

p
FigureΒ 1: Bivariate Chart