'Geom_line producing vertical lines with grouping
I am working on visualizing data (3-years, small timeframe but line graph is the preferred visualization) using geom_line(), but when I do, I get vertical lines in the plot, rather than an actual line graph. I am trying to group on type.
country_totals %>%
ggplot(aes(year, value, color = type, group = type)) +
geom_line() +
scale_y_continuous(labels = comma)

Solution 1:[1]
If you have several countries and you want the x axis to be years, shouldn't you group by year and type first?
country_totals %>%
group_by(year, type) %>%
summarize(value = sum(value)) %>%
...
Solution 2:[2]
This is because your date format is not correct. Instead of it understanding it as d-M-Y, it is understanding it as M-d-Y, so you have many values for each months but not days in between.
Try reformating your date:
df$Date <-as.Date(paste(df$Year, df$Momnth, 01), "%Y %m %d")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | choabf |
