ggplot2:不知道如何自动为标记为

时间:2018-10-30 21:49:30

标签: r ggplot2

我是R和SO的新手。目前,我必须写一个作业,到目前为止,R看起来很有趣!我们正在分析以GB为重点的欧洲社会调查的数据。我只想绘制变量income(1到10)的分布。

我使用的代码是:

library(ggplot2)
theme_set(theme_bw())
ggplot(GB, aes(x=income)) +
    geom_bar(width = .5, fill = "tomato3", na.rm = TRUE)
    labs(title="Income Distribution",
    caption = "Source: ESS7 (2014)")

这只是我尝试的一种方式。不断出现错误代码“ 不知道如何自动为标记为类型的对象选择刻度。默认为连续。”。由于我是用R Markdown编写作业,所以我希望摆脱它。

数据样本

> dput(dplyr::select(head(GB, 20), income))
    structure(list(income = structure(c(4, 2, 2, 6, 1, 5, 10, 2, 
    6, 7, 7, NA, NA, 4, 8, NA, 3, 6, 10, 1), labels = c(`J - 1st
    decile` = 1, `R - 2nd decile` = 2, `C - 3rd decile` = 3,
    `M - 4th decile` = 4, `F - 5th decile` = 5, `S - 6th decile` = 6,
    `K - 7th decile` = 7, `P - 8th decile` = 8, `D - 9th decile` = 9,
    `H - 10th decile` = 10, Refusal = 77, `Don't know` = 88,
    `No answer` = 99), class = "labelled")), row.names = c(NA, -20L),
    class = c("tbl_df", "tbl", "data.frame"))

有人可以帮忙吗? :)

编辑:我在代码中添加了factor-错误消息消失了,但即使我写了na.rm=TRUE,NA值仍包含在条形图中。有什么事吗使用的代码:

library(ggplot2)
theme_set(theme_bw())
ggplot(GB, aes(x=factor(income))) +
geom_bar(width = .5, fill="tomato3", na.rm = TRUE) +
labs(title="Verteilung des Haushaltseinkommens",
    caption = "Quelle: ESS7 (2014)")

NA

0 个答案:

没有答案