r语言画散点图,求指导

想要画出一个点阵图那样的等距散点图,就是用点铺满整个4x4的正方形,求指导

你可以使用 ggplot2 包来绘制等距散点图。以下是一个简单的例子:

library(ggplot2)

# 创建一个数据框,包含 x 和 y 坐标
df <- data.frame(x = rep(1:4, 4), y = rep(1:4, each = 4))

# 绘制等距散点图
ggplot(df, aes(x = x, y = y)) +
  geom_point() +
  scale_x_continuous(expand = c(0, 0), breaks = 1:4) +
  scale_y_continuous(expand = c(0, 0), breaks = 1:4) +
  theme_classic() +
  theme(panel.grid = element_blank())

这个例子中,我们首先创建了一个数据框,包含 x 和 y 坐标。然后使用 ggplot 函数创建一个绘图对象,并指定 x 和 y 坐标。接着使用 geom_point 函数添加散点图层。为了让散点图等距分布,我们使用 scale_x_continuous 和 scale_y_continuous 函数来设置 x 和 y 轴的刻度。最后使用 theme 函数来设置绘图的主题,包括去除网格线。

运行上述代码,你将得到一个等距散点图,其中点铺满了一个 4x4 的正方形。