2014-04-01 101 views
1

編輯:我繪製了一個有15個不同類別(Q002_1 - Q002_15)的Likert標度來回答,請參見下面的圖表。ggplot2缺少美學與二分變量

我現在想要的是將此圖(代碼如下)作爲二元變量與ggplot2一起繪製,有關詳細信息,請參閱this question

我收到以下錯誤信息:

Error: stat_bin requires the following missing aesthetics: x

我知道,我沒有看到明顯的痛苦這裏。誰能幫我嗎?

代碼:

competence_bachelor_dich <- competence_bachelor # dichotomous variable 

levels(competence_bachelor_dich) <- list("0" = c("insignificant", "2", "3"), 
         "1" = c("8", "9", "very relevant")) 

ggplot(rawdata, aes(x = competence_bachelor_dich)) + 
    geom_histogram() + xlab("") + ylab("Number of participants") + 
    scale_x_discrete(labels = "0", "1") + 
    ggtitle("How do you rate your skills gained with the Bachelor's?") + 
    theme(axis.text.y = element_text(colour = "black"), 
     axis.text.x = element_text(colour = "black")) 

ggsave((filename = "competence_bachelor_dich.pdf"), 
     scale = 1, width = par("din")[1], 
     height = par("din")[2], units = c("in", "cm", "mm"), 
     dpi = 300, limitsize = TRUE) 

enter image description here

+2

將dput(head(rawdata))的輸出添加到你的問題中。 – Roland

+0

請解釋你的數據集。從你以前的問題看'example.ods',這些列意味着什麼?例如,Q002_02,_03,... _15有什麼區別?此外,沒有一個值是「非常相關」或「微不足道」,儘管有1和10。 – jlhoward

+0

完成。我編輯了我原來的帖子。 –

回答

2

competence_bachelor_dich不在rawdata data.frame列。如果一切順利,應該是你的代碼應該工作,如果你添加rawdata$competence_bachelor_dich <- competence_bachelor_dich

+0

我得到的是以下錯誤消息:錯誤:stat_bin需要以下缺失的美學:x –