# 安装包
if (!requireNamespace("data.table", quietly = TRUE)) {
install.packages("data.table")
}if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}if (!requireNamespace("ggstatsplot", quietly = TRUE)) {
install.packages("ggstatsplot")
}
# 加载包
library(data.table)
library(jsonlite)
library(ggstatsplot)
散点图(Scatterstats)
环境配置
系统: Cross-platform (Linux/MacOS/Windows)
编程语言: R
依赖包:
data.table
;jsonlite
;ggpubr
;ggthemes
数据准备
# 加载数据
<- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/ggscatterstats/data.json")$exampleData$textarea[[1]])
data <- as.data.frame(data)
data
# 查看数据
head(data)
title year
1 Lord of the Rings: The Return of the King, The 2003
2 Lord of the Rings: The Fellowship of the Ring, The 2001
3 Lord of the Rings: The Two Towers, The 2002
4 Star Wars 1977
5 Star Wars: Episode V - The Empire Strikes Back 1980
6 Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb 1964
length budget rating votes mpaa genre
1 251 94.0 9.0 103631 PG-13 Action
2 208 93.0 8.8 157608 PG-13 Action
3 223 94.0 8.8 114797 PG-13 Action
4 125 11.0 8.8 134640 PG Action
5 129 18.0 8.8 103706 PG Action
6 93 1.8 8.7 63471 PG Comedy
可视化
# GGPubr 箱线图
<- ggscatterstats(
p data = data, x = rating, y = budget
)
p
