ここで最初の質問!2列のデータがあり、各行は値のペアです。最初の列と2番目の列を垂直にプロットし、値の各ペアを結ぶ線を作成します。これは、次のリンクの次の図のようになります。
http://www.sciencedirect.com/science/article/pii/S0300957297000440#gr1
R、python、perl、excelなどのツールでそれを行う方法を知っている場合は、私に知らせてください!
ここで最初の質問!2列のデータがあり、各行は値のペアです。最初の列と2番目の列を垂直にプロットし、値の各ペアを結ぶ線を作成します。これは、次のリンクの次の図のようになります。
http://www.sciencedirect.com/science/article/pii/S0300957297000440#gr1
R、python、perl、excelなどのツールでそれを行う方法を知っている場合は、私に知らせてください!
そして、and (and )R
を使用した別のアプローチmatpoints
matlines
boxplot
dd <- data.frame(x=rnorm(15), y= rnorm(15))
boxplot(dd, boxwex = 0.3)
# note that you need to transpose `dd`
matpoints(y= t(dd), x= c(1.17,1.83),pch=19, col='black')
matlines(y= t(dd), x= c(1.2,1.8), lty=1, col = 'black')
これがggplot2を使ったRアプローチで、少し速くて汚いです:
library(ggplot2)
df <- data.frame(baseline=c(1,1,2,2,3,3,4,5,6,7,8,9,10,11),
sixmos =c(5,6,5,7,8,9,10,12,12,2,1,5,2,3))
data <- data.frame(group = factor(1:nrow(df)),
cat=c(rep('baseline',nrow(df)),
rep('sixmos',nrow(df))),
values=c(df$baseline,df$sixmos))
ggplot(data, aes(x=cat, y=values)) +
geom_line(aes(group=group)) +
geom_point(aes(group=group)) +
geom_boxplot(data=df, aes(x='baselin', y=baseline)) +
geom_boxplot(data=df, aes(x='sixmos2', y=sixmos))
この回答も参照してください: グループ別の折れ線グラフ
Pythonでの非常に基本的な試みは次のとおりです。
import pylab as pl
data = pl.array([[1,2],[2,3],[1,3],[2,1],[5,3],[3,2],[3,2],[1,1]])
first = data[:,0]
second = data[:,1]
xs = []
ys = []
for r in data:
ys += list(r)
ys.append(None)
xs += [1.3,1.7]
xs.append(None)
pl.plot([1.3]*len(first),first,'o',[1.7]*len(second),second,'o',xs,ys)
pl.boxplot(data)
pl.ylim([min(min(first),min(second))-.5,max(max(first),max(second))+.5])
labels = ("first", "second")
pl.xticks([1,2],labels)
pl.show()
結果は次のようになります。
これは、を使用したRの概念実証ですsegments
。@mnelの回答に沿って、箱ひげ図をクリーンアップして追加しました。
first <- 1:10
second <- 2:11
boxplot(first,second, boxwex=0.3)
points(rep(c(1.2,1.8),each=10),c(first,second),pch=19)
segments(rep(1.2,10),first,rep(1.8,10),second,col="gray")
Rの別のオプションlattice
-最もきれいなものではありませんが、仕事をします:
#load packages
library(lattice)
library(latticeExtra)
#example data
B <- subset(OrchardSprays, treatment == "B")
D <- subset(OrchardSprays, treatment == "D")
BD <- rbind(B,D)
#create three separate plots
nobox = list(axis.line=list(col="transparent"))#to remove box around plots
boxplotB <- bwplot(decrease ~ treatment, B, ylab = NULL, ylim=c(0,70),
par.settings=nobox)
boxplotD <- bwplot(decrease ~ treatment, D, ylab = NULL, ylim=c(0,70),
par.settings=nobox)
plotBD <- xyplot(decrease ~ treatment, BD, col=1, ylim=c(0,70), pch=16,
par.settings=nobox, panel=function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.points(x, y, ...)
#this loop is required to create connections between points
for(i in 1:nrow(B))
panel.lines(1:2, c(y[i], y[i+nrow(B)]), alpha=0.5, ...)
}
)
#combine three plots
comb <- c(boxplotB, plotBD, boxplotD, layout = c(3,1), y.same = F)
update(comb, scales = list(at = list(NA, NA, NA), y = list(draw = FALSE)))