Perspective

Authors

[Editor] Hu Zheng;

[Contributors]

Note

Hiplot website

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

The three-dimensional perspective is a three-dimensional figure that can connect the higher values contained in a matrix with surfaces.

Setup

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

  • Programming language: R

  • Dependent packages: data.table; jsonlite; shape; ggplotify

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

# Load packages
library(data.table)
library(jsonlite)
library(shape)
library(ggplotify)

Data Preparation

The loaded data is a matrix.

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

# Convert data structure
data <- as.matrix(data)
col <- drapecol(data)

# View data
head(data[,1:5])
      V1  V2  V3  V4  V5
[1,] 100 101 102 103 104
[2,] 100 101 102 103 104
[3,] 101 102 103 104 105
[4,] 101 102 103 104 105
[5,] 101 102 103 104 105
[6,] 101 102 103 104 105

Visualization

# Perspective
p <- as.ggplot(function() {
  persp(as.matrix(data),
    theta = 45, phi = 20,
    expand = 0.5,
    r = 180, col = col,
    ltheta = 120,
    shade = 0.5,
    ticktype = "detailed",
    xlab = "X", ylab = "Y", zlab = "Z",
    border = "black" # could be NA
  )
  title("Perspective Plot", line = 0)
})

p
FigureΒ 1: Perspective

A clear view of a mountain peak.