データ
x <- 1:9
y <- 1:9
x1 <- c(7,4,6,2,9,3,8,1,6,3)
y1 <- c(3,6,5,8,3,4,2,9,2,6)
x2 <- c(6,3,4,9,1,8,4,2,5,7)
y2 <- c(7,8,2,1,7,9,6,3,5,4)
summary(data.frame(x1,y1,x2,y2))
## x1 y1 x2 y2
## Min. :1.00 Min. :2.0 Min. :1.00 Min. :1.00
## 1st Qu.:3.00 1st Qu.:3.0 1st Qu.:3.25 1st Qu.:3.25
## Median :5.00 Median :4.5 Median :4.50 Median :5.50
## Mean :4.90 Mean :4.8 Mean :4.90 Mean :5.20
## 3rd Qu.:6.75 3rd Qu.:6.0 3rd Qu.:6.75 3rd Qu.:7.00
## Max. :9.00 Max. :9.0 Max. :9.00 Max. :9.00
COL <- c(rgb(255,0, 0,105,max = 255),
rgb( 0,0,255,105,max = 255))
散布図
詳細
matplot(x,y,type = 'n',
main = '散布図',
xlab = 'X',
ylab = 'Y')
abline(lty = 2,
col = gray(0.5,0.25),
h = seq(1,9,1),
v = seq(1,9,1))
axis(side=1,at=1:9,labels=1:9)
axis(side=2,at=1:9,labels=1:9)
PCH <- 16:17
matpoints(x=x1,y=y1,pch = PCH[1],col = COL[1])
matpoints(x=x2,y=y2,pch = PCH[2],col = COL[2])
legend('topright',pch = PCH,col = COL,legend = c('(1)','(2)'))

plotly
library(plotly)
kyokasho <- list(size = 11,
color = 'blue',
family = 'UD Digi Kyokasho NK-R')
plot_ly() %>%
add_trace(x=x1,y=y1,name = '1',marker = list(color = COL[1])) %>%
add_trace(x=x2,y=y2,name = '2',marker = list(color = COL[2])) %>%
layout(barmode = 'group',
font = kyokasho,
title = '散布図',
xaxis = list(title = 'X'),
yaxis = list(title = 'Y'))
Python
import numpy as np
import matplotlib.pyplot as plt
x1 = [7, 4, 6, 2, 9, 3, 8, 1, 6, 3]
y1 = [3, 6, 5, 8, 3, 4, 2, 9, 2, 6]
x2 = [6, 3, 4, 9, 1, 8, 4, 2, 5, 7]
y2 = [7, 8, 2, 1, 7, 9, 6, 3, 5, 4]
plt.title('散布図',font='MS Gothic')
plt.xlabel('X')
plt.ylabel('Y')
plt.grid(linestyle = '--',color = (0.9, 0.9, 0.9, 0.25))
plt.scatter(x1,y1,color = (1.0, 0.0, 0.0, 0.5),label = '1',marker = 'o')
plt.scatter(x2,y2,color = (0.0, 0.0, 1.0, 0.5),label = '2',marker = '^')
plt.legend(loc = 'upper right')
plt.show()
