1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RAdvent Calendar 2024

Day 4

Rを学びたい Step3(散布図)

Posted at

はじめに

Rを学びたいStep3です。散布図を作成します。

plot_sample/scatter_plot.R
# PNGデバイスを開く
png("scatter_plot.png")

# 行列の作成
mat <- matrix(c(12, 2, 5, 8, 7, 10, 3, 6, 9, 4, 11, 1, 4, 7, 6, 9, 2, 5, 8, 3), nrow = 10, ncol = 2)

# 行列の内容を表示
print("行列の内容:")
print(mat)

# 散布図の作成
plot(mat[,1], mat[,2], xlab = "Column 1", ylab = "Column 2", main = "scatter", pch = 19, col = "blue")

# 回帰直線の追加
abline(lm(mat[,2] ~ mat[,1]), col = "red")

# PNGデバイスを閉じる
dev.off()

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?