首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scale_x_discrete不标注N/A值

scale_x_discrete不标注N/A值
EN

Stack Overflow用户
提问于 2014-01-04 21:43:36
回答 1查看 1.7K关注 0票数 2

我使用ggplot2绘制一个直方图,其中包含一些N/A值。当我标出x轴时,我的N/A条将保持无标记(1),但是当我没有标记我的直方图时,我的N/A值的自动标签就会出现(2)。

怎样才能使我的N/A值被贴上这样的标签?

(1)标记直方图-缺乏N/A值的标签!

代码语言:javascript
复制
doforaliving <- factor(rawdata$Q009)
ggplot(rawdata, aes(x=doforaliving)) + geom_histogram(binwidth=.5) + xlab("") + ylab("Number of Participants") + ggtitle("Are you working or studying?") + scale_x_discrete(breaks=c("1", "2", "3", "4", "na.value"), labels=c("Working", "Searching for work", "Continuing my studies", "Other", "NA"))

(2)未标记直方图-- N/A值被标记!

代码语言:javascript
复制
doforaliving <- factor(rawdata$Q009)
ggplot(rawdata, aes(x=doforaliving)) + geom_histogram(binwidth=.5) + xlab("") + ylab("Number of Participants") + ggtitle("Are you working or studying?")

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-04 23:56:45

根据您提供的信息,我想说:将na.value替换为NA

代码语言:javascript
复制
set.seed(1)
library(ggplot2)
rawdata <- data.frame(doforaliving=as.factor(c(sample(1:4, 100, replace=T), rep(NA, 10))))
ggplot(rawdata, aes(x=doforaliving)) + 
  geom_histogram(binwidth=.5) + xlab("") + 
  ylab("Number of Participants") + 
  ggtitle("Are you working or studying?") + 
  scale_x_discrete(breaks=c("1", "2", "3", "4",NA), 
                   labels=c("Working", "Searching for work", "Continuing my studies", "Other", "NA"))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20927743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档