Your date is structured 'yyyy-mm', so I'm guessing it's a character vector rather than a date object. You should convert it to class Date with as.Date()
and then it should work as expected. (You'll need to paste
on the day of the month.)
You get a grouping error because when your x-axis is a character vector, geom_line
will group by values of the character vector x-axis. Lines are drawn instead between the various y
values at each x
value. Here's an example using the geofacet
package's own state_ranks
dataset.
library(ggplot2)
library(dplyr)
library(geofacet)
data(state_ranks)
# The lines are not connected across a character x-axis.
ggplot(state_ranks) +
geom_line(aes(x = variable, y = rank))
# Throws error: geom_path: Each group consists of only one observation. Do
# you need to adjust the group aesthetic?
ggplot(state_ranks) +
geom_line(aes(x = variable, y = rank)) +
facet_geo(~ state)
If you group by state, you get the expected result (with an alphabetically ordered x-axis).
# Works, x-axis is alphabetized and lines are connected
ggplot(state_ranks) +
geom_line(aes(x = variable, y = rank, group = state)) +
facet_geo(~ state)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…