3

xyplot要素を並べ替える前に直線で接続すると、データ ポイント間の適切な連続した接続が得られます。

library(lattice)
fin <- read.csv("http://dl.dropbox.com/u/2505196/unc_vall.csv", header=T)
xyplot(acceptability ~ character | motion, data=fin, col=1, 
       aspect="xy", layout=c(6,1), type="o", scales = list(x = list(rot = 90)))

ここに画像の説明を入力

次に、要素を並べ替えると、すべてが台無しになります。

fin$character <- factor(fin$character, levels = c("battle","klank","manny",
                        "skelly","zombie","loman","himan"))

ここに画像の説明を入力

因子のレベルの並べ替えは正常に機能し、値は本来あるべき場所に移動しますが、どういうわけか線接続の順序は同じままです。並べ替えを変更して機能させる方法は思い浮かびません。

編集: ソリューションは、パッケージの両方xyplotで機能するのに十分なほど普遍的である必要があることを追加する必要があります。xYplotHmisc

4

3 に答える 3

3

線は、データに表示されている順序で描画されると思います。したがって、正しい順序を取得したい場合は、次のようにすることができます。

xyplot(acceptability ~ character | motion, data=fin[order(fin$character),], col=1, 
aspect="xy", layout=c(6,1), type="o", scales = list(x = list(rot = 90)))

data引数だけが変更されていることに注意してください。

于 2012-10-24T12:38:57.480 に答える
2

より良い解決策は、偽物ではなくデータをそのまま扱うことだと思います。ここでのx軸は要因であり、それを尊重する必要があります。使用したいことを実現できますが、カスタム関数でpanel.average()呼び出す必要もあります。panel.xyplot()panel

xyplot(acceptability ~ character | motion, data=fin, col=1, 
       aspect="xy", layout=c(6,1), scales = list(x = list(rot = 90)),
       panel = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           panel.average(x, y, horizontal = FALSE, ...)
       })

type = "a"ショートカットが私たちの呼び出しを追加するので、完全に感謝panel.average()します。それで、プロットを次のように変更します。

xyplot(acceptability ~ character | motion, data=fin, col=1, 
       aspect="xy", layout=c(6,1),
       type = c("p","a"), ## specify the type!
       scales = list(x = list(rot = 90)))
于 2012-10-24T12:52:12.543 に答える
2

Setting type=c("a", "p") (in place of type="o") will do the trick:

xyplot(acceptability ~ character | motion, data=fin, col=1,
       aspect="xy", layout=c(6,1), type=c("a", "p"), 
       scales = list(x = list(rot = 90)))
于 2012-10-24T12:47:38.420 に答える