Ridge

Authors

[Editor] Hu Zheng;

[Contributors]

Note

Hiplot website

This page is the tutorial for source code version of the Hiplot Ridge 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/ridge?lang=en

The ridge map is a graph that connects points and forms a ridge.

Setup

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

  • Programming language: R

  • Dependent packages: ggridges; ggplot2; ggthemes

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

# Load packages
library(ggridges)
library(ggplot2)
library(ggthemes)

Data Preparation

The loaded data are three groups and their corresponding values.

# Load data
data <- read.delim("files/Hiplot/154-ridge-data.txt", header = T)

# Convert data structure
data$group <- factor(data$group, levels = unique(data$group)[length(unique(data$group)):1])

# View data
head(data)
  value group
1   5.1    G1
2   4.9    G1
3   4.7    G1
4   4.6    G1
5   5.0    G1
6   5.4    G1

Visualization

# Ridge
p <- ggplot(data, aes(x = value, y = group, fill = group, col = group)) +
  geom_density_ridges(scale = 5, alpha = 0.8) +
  labs(x = "value", y = "group") +
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = "none") +
  ggtitle("Ridge Plot") +
  guides(color = guide_legend(reverse = TRUE),
         fill = guide_legend(reverse = TRUE)) +
  scale_fill_manual(values = c("#e04d39","#5bbad6","#1e9f86")) +
  scale_color_manual(values = c("#e04d39","#5bbad6","#1e9f86")) +
  theme_stata() +
  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,vjust = 1),
        legend.position = "right",
        legend.direction = "vertical",
        legend.title = element_text(size = 10),
        legend.text = element_text(size = 10))

p
FigureΒ 1: Ridge

Different colors represent different groups, and the approximate degree of data can be observed.