我正在尝试绘制ggplot线图,但是当我添加color
变量时却出现了一条奇怪的线:我使用的代码是:
df %>%
ggplot(aes(x = date, y = value)) +
geom_line(aes(color = as.factor(myColor))) +
facet_wrap(~myFacet) +
geom_vline(xintercept = as.Date("2016-11-30"), size= 1) +
geom_vline(xintercept = as.Date("2017-11-30"), size = 1) +
geom_vline(xintercept = as.Date("2018-11-30"), size = 1) +
theme_minimal()
但是,当我运行以下命令(删除颜色变量)时,我得到了正确的结果。
df %>%
ggplot(aes(x = date, y = value)) +
geom_line() +
facet_wrap(~myFacet) +
geom_vline(xintercept = as.Date("2016-11-30"), size= 1) +
geom_vline(xintercept = as.Date("2017-11-30"), size = 1) +
geom_vline(xintercept = as.Date("2018-11-30"), size = 1) +
theme_minimal()
正确的情节:
不正确的情节:
我在这里指的线是图形的绿色部分和图形的蓝色部分上的直线(分别为2018和2019)
数据如下:
# A tibble: 26,304 x 3
date value myFacet
<date> <dbl> <chr>
1 2016-09-01 40 some text
2 2016-09-02 69 some text
3 2016-09-03 69 some text
4 2016-09-04 64 some text
5 2016-09-05 80 some text
6 2016-09-06 79 some text
7 2016-09-07 75 some text
8 2016-09-08 53 some text
9 2016-09-09 44 some text
10 2016-09-10 53 some text
# ... with 26,294 more rows
数据太大,无法在此处输入。