You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用R复现指定网站的3D散点图并生成出版可用格式?

复现目标3D散点图的方案及出版级格式建议

一、核心特征识别

从你提供的图来看,核心元素包括:

  • 带刻度与标签的三维坐标轴
  • 按类别区分颜色的散点
  • 简洁无冗余的背景布局
  • 固定视角的静态展示

二、推荐R包及代码示例

1. scatterplot3d(静态矢量图,适配出版需求)

这个包生成的是可编辑的静态矢量图,细节调整灵活,适合出版场景:

# 安装加载包
install.packages("scatterplot3d")
library(scatterplot3d)

# 替换为你的自有数据
set.seed(123)
data <- data.frame(
  x = rnorm(100),
  y = rnorm(100),
  z = rnorm(100),
  group = sample(c("组1", "组2", "组3"), 100, replace = TRUE)
)

# 定义类别颜色映射
color_map <- c("组1" = "#1f77b4", "组2" = "#ff7f0e", "组3" = "#2ca02c")

# 绘制3D散点图
s3d <- scatterplot3d(
  data$x, data$y, data$z,
  color = color_map[data$group],
  pch = 16, # 实心点更适合出版
  xlab = "X轴名称", ylab = "Y轴名称", zlab = "Z轴名称",
  grid = FALSE, # 移除网格保持简洁
  box = TRUE, # 保留坐标轴边框
  angle = 45, # 调整视角匹配目标图
  cex.symbols = 1.2, # 散点大小
  cex.lab = 1.1, # 坐标轴标签大小
  cex.axis = 0.9 # 刻度文字大小
)

# 添加图例
legend(
  s3d$xyz.convert(-2, 2, 2), # 定位图例位置
  legend = names(color_map),
  col = color_map,
  pch = 16,
  bty = "n", # 移除图例边框
  cex = 1
)

2. rgl(可交互调视角,支持高清导出)

如果需要手动调整视角后导出,rgl的灵活性更强,支持导出PDF/PNG等出版级格式:

# 安装加载包
install.packages("rgl")
library(rgl)

# 使用上述模拟数据(替换为你的数据)
open3d()
plot3d(
  data$x, data$y, data$z,
  col = color_map[data$group],
  size = 3,
  xlab = "X轴名称", ylab = "Y轴名称", zlab = "Z轴名称",
  axes = TRUE,
  box = TRUE,
  aspect = c(1,1,1)
)

# 添加图例
legend3d(
  "topright",
  legend = names(color_map),
  col = color_map,
  pch = 16,
  cex = 1
)

# 调整到合适视角后导出
rgl.postscript("3d_plot.pdf", "pdf") # 矢量PDF,适配专业排版软件
rgl.snapshot("3d_plot.png", fmt = "png", top = TRUE) # 高清PNG

3. plot3D(ggplot2风格,定制性强)

如果习惯ggplot2语法,可使用这个包实现风格统一:

install.packages("plot3D")
library(plot3D)

scatter3D(
  x = data$x, y = data$y, z = data$z,
  col = color_map[data$group],
  pch = 16,
  xlab = "X轴名称", ylab = "Y轴名称", zlab = "Z轴名称",
  bty = "g", # 简洁背景样式
  theta = 45, phi = 20, # 视角参数
  cex = 1.2,
  ticktype = "detailed" # 清晰刻度样式
)
legend("topright", legend = names(color_map), col = color_map, pch = 16, bty = "n")

三、出版级格式优化要点

  • 优先导出矢量格式:选择PDF格式,保证缩放后不失真,适配LaTeX、InDesign等排版工具。
  • 配色专业合规:避免高饱和度颜色,若需黑白印刷,可配合不同形状(pch参数)区分组别。
  • 字体统一规范:将坐标轴标签、刻度的字体设置为出版要求的字体(如Times New Roman),可通过par(family = "serif")或对应包的字体参数调整。
  • 精简视觉元素:移除不必要的网格、背景色,突出数据本身。
  • 标注清晰可读:确保坐标轴标签、图例文字字号符合出版规范(通常8-12pt),避免过小或过大。

内容的提问来源于stack exchange,提问作者FlyingDutch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 03:10:56