x <- 1:100
n <- length(x)
set.seed(5)
d <- data.frame(
u = rnorm(n, mean = 0, sd = 1),
v = rnorm(n, mean = 2, sd = 2),
w = rnorm(n, mean = -2, sd = 3))
# カラーパレット
COL <- c(rgb(255, 0, 0, 105, max = 255), # 赤
rgb( 0, 0, 255, 105, max = 255), # 青
rgb( 0, 155, 0, 105, max = 255)) # 緑
x1 <- c(7,4,6,2,9,3,8,1,6,3)
y1 <- c(3,6,5,8,3,4,2,9,2,6)
matplot(x, d, type = 'p', pch = colnames(d))

x2 <- c(6,3,4,9,1,8,4,2,5,7)
y2 <- c(7,8,2,1,7,9,6,3,5,4)
matplot(x, d, type = 'p', pch = 16, col = COL,
main = 'タイトル',
xlab = 'x軸',
ylab = 'y軸')
# 格子線(grid lines)
grid()

# 凡例(はんれい)
# 図枠
matplot(x, d, type = 'n', # typeは'n'でプロットなし
ylim = c(-10, 10),
main = '散布図',
xlab = 'x軸',
ylab = 'y軸')
# 格子線(grid lines)
abline(lty = 2, # 線種(2:点線)
col = gray(0.5, 0.25), # 灰色(濃さ,透過率)
h = seq(-10, 10, 5), # 水平線; horizontal lines
v = seq(0, 100, 20)) # 垂直線; vertical lines
# 作図
PCH <- 16:18
matpoints(x, d$u, pch = PCH[1], col = COL[1])
matpoints(x, d$v, pch = PCH[2], col = COL[2])
matpoints(x, d$w, pch = PCH[3], col = COL[3])
# 凡例(はんれい)
legend('topright', pch = PCH, col = COL, legend = colnames(d))

pairs(d, pch = 16, col = COL[1])

library(plotly)
## 要求されたパッケージ ggplot2 をロード中です
##
## 次のパッケージを付け加えます: 'plotly'
## 以下のオブジェクトは 'package:ggplot2' からマスクされています:
##
## last_plot
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter
## 以下のオブジェクトは 'package:graphics' からマスクされています:
##
## layout
# フォント設定
kyokasho <- list(size = 11, color = 'blue', family = 'UD Digi Kyokasho NK-R')
plot_ly() |>
add_trace(x = x, y = d$u, name = 'u', marker = list(color = COL[1])) |>
add_trace(x = x, y = d$v, name = 'v', marker = list(color = COL[2])) |>
add_trace(x = x, y = d$w, name = 'w', marker = list(color = COL[3])) |>
layout(barmode = 'group',
font = kyokasho,
title = '散布図',
xaxis = list(title = 'x軸'),
yaxis = list(title = 'y軸', range = c(-10, 10)))
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode