格子プロット内の異なるグループに異なるシンボルを割り当てるにはどうすればよいですか?
質問
プロットにそれぞれ3つのドットを持つ3つのグループがあり、3つのグループの3つのドットがすべて異なるシンボルで表示される白黒バージョンが必要だとします。パネルを指定するにはどうすればよいですか?
http://www.r-bloggers.com/working-with-themes-in-lattice-graphics/http://stat.ethz.ch/r-manual/r-devel/library/lattice/html/panel.superpose.html
解決
私はあなたがリンクしたブログ投稿でレイアウトしたのと同じ一般的な戦略を使用する傾向があります。
で始まります standard.theme()
, 、自分のニーズに最適なカスタマイズされたテーマができるまで、設定に微調整を行うことができます。好きなものができたら、 par.settings
あなたがそれを使用したいときはいつでも議論。
library(lattice)
# Start work on your own black-and-white theme
myTheme <- standard.theme(col = FALSE)
myTheme$superpose.symbol$pch <-1:7
# These are the kinds of commands you can use to explore the list of available
# settings as well as their current settings.
names(myTheme)
myTheme$superpose.symbol
# Compare the results of your own theme to those produce by lattice's
# default settings.
library(gridExtra)
p1 <- xyplot(Sepal.Length ~ Petal.Length, group= Species, data = iris,
main = "lattice's default theme")
p2 <- xyplot(Sepal.Length ~ Petal.Length, group= Species, data = iris,
par.settings = myTheme,
main = "My customized theme")
grid.arrange(p1, p2, ncol=2)
他のヒント
より簡単な方法があるかもしれません(私は格子にひどく精通していません)が、:
library(lattice)
df <- data.frame(x = rnorm(9), y = rnorm(9), z= letters[1:3])
xyplot(x~y,data=df,groups=z,
par.settings=list(superpose.symbol=list(pch=1:3,
col='black')))
これに基づいた別のソリューションがあります panel.superpose
, 、あなたがあなたの質問で参照してください:
library(lattice)
xyplot(Sepal.Length ~ Petal.Length, groups = Species, data = iris,
panel = function(x,y,...){
panel.superpose(x,y,..., pch=list("A","O","X"))
})
lattice
使用します 一次変数 (プライマリディスプレイを定義します)、 コンディショニング変数 (さまざまなパネルで並置されたサブグループを定義します)、および グループ化変数 (パネル内に重ねられたサブグループを定義します)。
式 sepal.length〜petal.length およびグループ化ステートメント グループ=種 プロットするデータを指定し、に渡す panel
プロットを制御します。グループ!= nullの場合 panel.superpose
割り当てられたリストのi番目の要素を渡します pch
i番目のレベルまで groups
.
使用 ...
為に panel
と panel.superpose
すべての関数引数の定義を避け、カスタマイズされるもののみを述べることができます。
pars.settings
とは異なり、特定のオブジェクトにカスタム設定を添付します lattice.options
グローバルに設定に影響します。