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?

More than 3 years have passed since last update.

Rで散布図を描く ---初心者向け---

Posted at
tags: rBasicLearning

散布図

使用するデータ

今回は, データとしてmtcarsを使う.

library(datasets)
mtcars

散布図を使う場合

ヒストグラムは, 二つの量的データの関係性の概観を見る時に使う.

まずは, 量的データの概観を一つずつヒストグラムで見ていく

まずは, それぞれの変数のヒストグラムを見て, 概観を掴む.

hist(mtcars$wt)
hist(mtcars$mpg)

散布図をプロットする

散布図は, 以下のコードで書くことができる.

plot(mtcars$wt, mtcars$mpg)

散布図に装飾を加える

散布図は, 以下のように装飾を加えることができる.
pchは, プロットの点の種類(pch = 19は丸)
cexは, プロットのサイズの拡大・縮小を表す(cex = 1.5は, プロットのサイズを1.5倍にする)
colは色, mainはグラフのタイトル, xlabはx軸ラベル, ylabはy軸ラベル.

plot(mtcars$wt, mtcars$mpg,
  pch = 19,         # Solid circle
  cex = 1.5,        # Make 150% size
  col = "#cc0000",  # Red
  main = "MPG as a Function of Weight of Cars",
  xlab = "Weight (in 1000 pounds)",
  ylab = "MPG")

plot(mtcars$wt, mtcars$mpg,
     pch = 3,         # plus mark
     cex = 1.5,        # Make 150% size
     col = "#cc0000",  # Red
     main = "MPG as a Function of Weight of Cars",
     xlab = "Weight (in 1000 pounds)",
     ylab = "MPG")

plot(mtcars$wt, mtcars$mpg,
     pch = 19,         # Solid circle
     cex = 0.3,        # Make 30% size
     col = "#cc0000",  # Red
     main = "MPG as a Function of Weight of Cars",
     xlab = "Weight (in 1000 pounds)",
     ylab = "MPG")

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?