ggplot2缺少二元变量的美学

时间:2014-04-01 13:56:13

标签: r ggplot2 aesthetics

编辑:我已经绘制了一个具有15个不同类别(Q002_1 - Q002_15)的Likert量表来回答,请参阅下面的图表。

我现在想要的是将此图(下面的代码)绘制为ggplot2的二分变量,有关详细信息,请参阅this question

我收到以下错误消息:

  

错误:stat_bin需要以下缺失的美学: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

1 个答案:

答案 0 :(得分:2)

competence_bachelor_dich不是rawdata data.frame中的列。如果添加rawdata$competence_bachelor_dich <- competence_bachelor_dich

,那么所有内容都应该是您应该使用的代码