包含两个不同分组的GGPLOT返回R中的空图
这是我的示例数据框。
我将显示具有不同颜色和不同线类型的不同颜色的不同GRP s。并将这两个作为传奇。
library(dplyr)
library(ggplot2)
seed(123)
df <- data.frame(date = rep(c("Jan-2010", "Feb-2010", "Mar-2010", "Apr-2010" ,"Dec-2009"),each=5),
grp = c(LETTERS[1:5], LETTERS[2:6], LETTERS[1:5],LETTERS[3:7], LETTERS[1:5]),
subgrp = c("x","x","x","y","y","x","x","y","y","y","x","x","x","y","y",
"x","y","y","y","y","x","x","x","y","y"),
value = sample(4:10, 25, replace=TRUE))
df
date grp subgrp value
1 Jan-2010 A x 7
2 Jan-2010 B x 10
3 Jan-2010 C x 6
4 Jan-2010 D y 4
5 Jan-2010 E y 5
6 Feb-2010 B x 7
7 Feb-2010 C x 5
8 Feb-2010 D y 4
9 Feb-2010 E y 6
10 Feb-2010 F y 7
11 Mar-2010 A x 8
12 Mar-2010 B x 10
13 Mar-2010 C x 7
14 Mar-2010 D y 10
15 Mar-2010 E y 5
16 Apr-2010 C x 4
17 Apr-2010 D y 9
18 Apr-2010 E y 7
19 Apr-2010 F y 5
20 Apr-2010 G y 5
21 Dec-2009 A x 6
22 Dec-2009 B x 8
23 Dec-2009 C x 6
24 Dec-2009 D y 8
25 Dec-2009 E y 9
但是即使为了分组,它也会返回一个空图。
df %>%
ggplot() +
geom_line(aes(x=date,
y=value,
color=grp))
我感谢任何提示或帮助解决此问题。
this is my sample dataframe.
I am going to show different grp s with different color and different subgrp s with different line types. and shows these two as legends.
library(dplyr)
library(ggplot2)
seed(123)
df <- data.frame(date = rep(c("Jan-2010", "Feb-2010", "Mar-2010", "Apr-2010" ,"Dec-2009"),each=5),
grp = c(LETTERS[1:5], LETTERS[2:6], LETTERS[1:5],LETTERS[3:7], LETTERS[1:5]),
subgrp = c("x","x","x","y","y","x","x","y","y","y","x","x","x","y","y",
"x","y","y","y","y","x","x","x","y","y"),
value = sample(4:10, 25, replace=TRUE))
df
date grp subgrp value
1 Jan-2010 A x 7
2 Jan-2010 B x 10
3 Jan-2010 C x 6
4 Jan-2010 D y 4
5 Jan-2010 E y 5
6 Feb-2010 B x 7
7 Feb-2010 C x 5
8 Feb-2010 D y 4
9 Feb-2010 E y 6
10 Feb-2010 F y 7
11 Mar-2010 A x 8
12 Mar-2010 B x 10
13 Mar-2010 C x 7
14 Mar-2010 D y 10
15 Mar-2010 E y 5
16 Apr-2010 C x 4
17 Apr-2010 D y 9
18 Apr-2010 E y 7
19 Apr-2010 F y 5
20 Apr-2010 G y 5
21 Dec-2009 A x 6
22 Dec-2009 B x 8
23 Dec-2009 C x 6
24 Dec-2009 D y 8
25 Dec-2009 E y 9
but even for grouping, it returns an empty plot.
df %>%
ggplot() +
geom_line(aes(x=date,
y=value,
color=grp))
I would appreciate any hint or help to fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论