0
안녕하세요. 두 코드 세트가 서로 다른 경우에도 다른 플롯을 제공합니다.ggplot은 geom_bar를 사용하여 동일한 변수와 값을 가진 다른 코드 세트에 대해 동일한 플롯을 제공하지 않습니다.
por %>%
group_by(sex,romantic) %>%
summarise(n=mean(G3,na.rm=T)) %>%
ggplot(aes(x=sex, y=n, fill=romantic)) +
geom_bar(position="dodge",stat="identity") +
ggtitle("Romantic Relationship, Grades and Gender")
CODE : 2 : 코드 (2) (2) 코드와 같은 정확한 플롯 1.
CODE 1 포기하지 않는 코드에 어떤 실수가 있으면 친절하게 도와
q <-summarise(por,n=mean(G3,na.rm=T))
ggplot(por, aes(sex, as.numeric(q), fill = romantic)) +
geom_bar(position="dodge",stat="identity") +
ggtitle("Romantic Relationship,Grades and Gender")
---- 여기에서는 구조 --- 첫 번째 코드에서
str(por) 'data.frame': 649 obs. of 6 variables:
$ sex : chr "F" "F" "F" "F" ...
$ age : int 18 17 15 15 16 16 16 17 15 15...
$ romantic : chr "no" "no" "no" "yes" ...
$ G1 : int 0 9 12 14 11 12 13 10 15 12 ...
$ G2 : int 11 11 13 14 13 12 12 13 16 12 ...
$ G3 : int 11 11 12 14 13 13 13 13 17 13 ...
code2의 'n'은 어떤 것으로도 그룹화되지 않으므로 총체적으로 'sex'및 'romantic'로 나누지 않습니다. 게다가 당신은 데이터 소스의 외부에있는 미학을 사용해서는 안되며,'ggplot'은 에러를 내거나 줄 것입니다. Cfr의 결과는 첫 번째 플롯에 전달되는 내용 인'por %> % group_by (sex, romantic) %> % summarize (n = mean (G3, na.rm = T))' por, n = 평균 (G3, na.rm = T))' – GGamba