I have a data df
with the format
State | Date | Ratio |
---|---|---|
AL | 2019-01 | 10.1 |
AL | 2019-02 | 12.1 |
... | ... | ... |
NY | 2019-01 | 15.1 |
... | ... | ... |
I have a data df
with the format
State | Date | Ratio |
---|---|---|
AL | 2019-01 | 10.1 |
AL | 2019-02 | 12.1 |
... | ... | ... |
NY | 2019-01 | 15.1 |
... | ... | ... |
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)