Group Line

Authors

[Editor] Hu Zheng;

[Contributors]

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; ggplot2

# Install packages
if (!requireNamespace("data.table", quietly = TRUE)) {
  install.packages("data.table")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
  install.packages("jsonlite")
}
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2")
}

# Load packages
library(data.table)
library(jsonlite)
library(ggplot2)

Data Preparation

# Load data
data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/group-line/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)

# View data
head(data)
  x        y names groups
1 1 2.253573    L1      A
2 2 2.231082    L1      A
3 3 1.740380    L1      A
4 4 2.255786    L1      A
5 5 2.429561    L1      A
6 6 1.951557    L1      A

Visualization

# Group Line
p <- ggplot(data, aes(x = x, y = y, group = names, color = groups)) +
  geom_line() +
  geom_point() +
  scale_color_manual(values = c("#e04d39","#5bbad6")) +
  theme_bw()

p
FigureΒ 1: Group Line