Ggplot:如何 select 图表中的字符串值?
Ggplot : How to select a string value for in a graph?
这是我的问题:
我想在 R 中制作彩票图。我有一个名为 "loto" 的数据集,其中包含 2000 种不同的抽奖方式。
我想制作这种类型的图表,但是,每天。 "jour_de_tirage" -> 星期一、星期三和星期六我有 3 个不同的日子。
--> 我要 select 字符串 "Monday" ("Lundi")
这是上图的代码,但是不知道在哪可以添加过滤器,按天过滤。
loto %>%
select(boule_1, boule_2, boule_3, boule_4, boule_5) %>%
gather(key = key, value = value) %>%
ggplot(aes(x = value, fill = key))
我试过了:
loto %>%
select(jour_de_tirage) %>%
group_by(loto$boule_1, loto$boule_2, loto$boule_3, loto$boule_4, loto$boule_5) %>%
ggplot(x = jour_de_tirage["Lundi"], y = numbers[1:49]) + geom_bar()
ggtitle("Monday Lottery Stats")
这段代码有一些错误,我没有找到问题所在...
你能帮帮我吗?谢谢
关闭@Annet 的评论,您应该在调用 select
和 gather
之前添加 filter
:
loto %>%
filter(jour_de_tirage == "Lundi") %>%
select(boule_1, boule_2, boule_3, boule_4, boule_5) %>%
gather(key = key, value = value) %>%
ggplot(aes(x = value, fill = key))
这是我的问题: 我想在 R 中制作彩票图。我有一个名为 "loto" 的数据集,其中包含 2000 种不同的抽奖方式。 我想制作这种类型的图表,但是,每天。 "jour_de_tirage" -> 星期一、星期三和星期六我有 3 个不同的日子。
--> 我要 select 字符串 "Monday" ("Lundi")
这是上图的代码,但是不知道在哪可以添加过滤器,按天过滤。
loto %>%
select(boule_1, boule_2, boule_3, boule_4, boule_5) %>%
gather(key = key, value = value) %>%
ggplot(aes(x = value, fill = key))
我试过了:
loto %>%
select(jour_de_tirage) %>%
group_by(loto$boule_1, loto$boule_2, loto$boule_3, loto$boule_4, loto$boule_5) %>%
ggplot(x = jour_de_tirage["Lundi"], y = numbers[1:49]) + geom_bar()
ggtitle("Monday Lottery Stats")
这段代码有一些错误,我没有找到问题所在...
你能帮帮我吗?谢谢
关闭@Annet 的评论,您应该在调用 select
和 gather
之前添加 filter
:
loto %>%
filter(jour_de_tirage == "Lundi") %>%
select(boule_1, boule_2, boule_3, boule_4, boule_5) %>%
gather(key = key, value = value) %>%
ggplot(aes(x = value, fill = key))