理学療法士がまとめたノート

統計学備忘録(R言語のメモ)

since2016 ときどきTEXのメモ

対応のあるデータのグラフ

id <- 1:5
x <- c(rnorm(5, 20, 2))
y <- c(rnorm(5, 25, 1))
data <- data.frame(id, x, y)

  id        x        y
1  1 22.83957 23.13902
2  2 15.05851 23.15993
3  3 19.49754 24.70116
4  4 17.43654 26.60801
5  5 17.01846 25.09940

x <- c(1,2)
t_data <- t(data[,2:3])

      [,1]     [,2]     [,3]     [,4]     [,5]
x 22.83957 15.05851 19.49754 17.43654 17.01846
y 23.13902 23.15993 24.70116 26.60801 25.09940

matplot(x, t_data, type = "l", lty = 1)
legend("topleft", legend=id, col = id,  lty = 1)

f:id:yoshida931:20220125222246p:plain:w500

id <- 1:20
group <- c(rep("A",10),rep("B",10))
x <- c(rnorm(10,20,2), rnorm(10,15,3))
y <- c(rnorm(10,25,1), rnorm(10,20,0.5))
data <- data.frame(id, group, x, y)

x <- c(1,2)
t_data <- t(data[,3:4])
mg <- ifelse(data$group == "A", 1, 2)
matplot(x, t_data, type = "l", lty = 1, pch = 1, col = mg, xlab = "", ylab = "",xaxt="n", xlim = c(0.9,2.1))
name<-c("前","後")
axis(side=1,at=c(1, 2),labels=name)  #指定した場所に挿入
legend(1.8, 15, c("治療A","治療B"), col = c(1, 2), lty = 1)

f:id:yoshida931:20190711140353p:plain:w500