r質問プロットしているときの不明の空想の因子の組み合わせ
質問
ライブラリーからのEX0622データを使用しています2
library(Sleuth2)
library(lattice)
attach(ex0622)
#Using the 'rep()' function to create a vector for the sexual preference variable ('Hetero' or 'Homo')
sex.pref=as.factor(c(rep("Hetero", 16), rep("Homo", 19), rep("Hetero", 6)))
#Using the 'rep()' function to create a vector for the Type of Death variable ('AIDS' or 'Non-AIDS')
death.type=c(rep("Aids",6), rep("Non-Aids",10), rep("Aids", 19), "Aids", rep("Non-Aids", 5))
#creating a vector of gender variable
gender=(c(rep("Male", 35), rep("Female", 6)))
length(death.type)
ex0622_alt=as.data.frame(cbind(ex0622, gender, sex.pref, death.type))
ex0622_alt
.
事前依存コードを実行して、データ・セットにいくつかの要因を追加します。それから私はラティスパッケージで変数の特定の組み合わせを表示したいです。
histogram(~Volume[sex.pref=="Hetero"]|gender, data=ex0622_alt, main="Heterosexuals")
dotplot(Volume[sex.pref=="Hetero"]~gender, col=1)
.
両方の試みの両方が、要因とSex.prefの空の組み合わせを生成してください。何が起こっているのかわかりません。
あらゆる助けが理解されるでしょう!
ありがとう!
解決
Your problem is in the histogram
call: Within the ex0622_alt
data-frame, you're subsetting the Volume
variable by sex.pref == "Hetero"
, but you're not subsetting the gender
variable at all, so the Volume
subvector and the gender
variable don't have the same length, so results will be strange. It works if you do:
histogram(~Volume[sex.pref=="Hetero"] |
gender[sex.pref=='Hetero'], data=ex0622_alt, main="Heterosexuals")
Or you could just use the subset
arg, which would be more natural:
histogram(~Volume | gender,
data = ex0622_alt, subset = sex.pref == 'Hetero', main="Heterosexuals")
Same comment (and fix) applies to the dotplot
command.
所属していません StackOverflow