我使用ggplot2绘制一个直方图,其中包含一些N/A值。当我标出x轴时,我的N/A条将保持无标记(1),但是当我没有标记我的直方图时,我的N/A值的自动标签就会出现(2)。
怎样才能使我的N/A值被贴上这样的标签?
(1)标记直方图-缺乏N/A值的标签!
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值被标记!
doforaliving <- factor(rawdata$Q009)
ggplot(rawdata, aes(x=doforaliving)) + geom_histogram(binwidth=.5) + xlab("") + ylab("Number of Participants") + ggtitle("Are you working or studying?")

发布于 2014-01-04 23:56:45
根据您提供的信息,我想说:将na.value替换为NA
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"))

https://stackoverflow.com/questions/20927743
复制相似问题