2017-12-04 3 views
3

2 레벨 인자 변수를 사용하여 조건부 밀도 플롯을 플롯하려고합니다. 이 변수는 원래 3 수준 요소 변수 였지만 3 요소 수준 중 2 가지만 사용하여 데이터 프레임 (microtus.train)을 구성했습니다. 조건부 밀도 그림을 그릴 때 "y 축"의 요소 수준은 "microtus.train"을 구성 할 때 제외시킨 수준 인 "알 수 없음"으로 표시됩니다. 아래 그림을 참조하십시오.조건부 밀도 2 레벨 인자 변수를 사용하는 플롯

enter image description here

나는 여전히 남아있는 이유를 모르겠습니다. 누군가이 문제를 해결할 수있는 방법을 안내해 줄 수 있습니까? 수정 후, 나는 "멀티 플렉스"와 "지하"를 y 축의 라벨로보아야합니다.

내 코드는 다음과 같습니다 :

library(Flury) 
data(microtus, package = "Flury") 

# Creating training data frame 
microtus.train <- subset(microtus, 
    microtus$Group %in% c("multiplex", "subterraneus"), 
    select = c("Group", "M1Left", "M2Left", "M3Left", "Foramen", "Pbone", 
      "Length", "Height", "Rostrum")) 
# Plot Conditional Density plot of Group given M1Left 
cdplot (Group ~ M1Left, data = microtus.train) 

사전에 감사합니다!

답변

0

Group의 세 번째 수준에 해당하는 행을 제거했지만 Group 열은 여전히 ​​3 개의 수준 (두 개만 현재 데이터에 있음)의 요소로 코딩되어 여전히 cdplot 기능. droplevels을 사용하여 빈 레벨을 제거하십시오.

str(microtus.train$Group) 
Factor w/ 3 levels "multiplex","subterraneus",..: 1 1 1 1 1 1 1 1 1 1 ... 
microtus.train$Group = droplevels(microtus.train$Group) 
str(microtus.train$Group) 
Factor w/ 2 levels "multiplex","subterraneus": 1 1 1 1 1 1 1 1 1 1 ... 
# Plot Conditional Density plot of Group given M1Left 
cdplot (Group ~ M1Left, data = microtus.train) 

enter image description here