I am trying to make a line graph in ggplot and I am having difficulty diagnosing my error. I've read through nearly all the similar threads, but have been unable to solve my issue.
I am trying to plot Japanese CPI. I downloaded the data online from FRED.
my str looks like:
str(jpycpi)
data.frame: 179 obs. of 2 variables:
$ DATE : Factor w/ 179 levels "2000-04-01","2000-05-01",..: 1 2 3 4 5 6 7 8 9 10 ...
$ JPNCPIALLMINMEI: num 103 103 103 102 103 ...
My code to plot:
ggplot(jpycpi, aes(x=jpycpi$DATE, y=jpycpi$JPNCPIALLMINMEI)) + geom_line()
it gives me an error saying:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
I have tried the following and have been able to plot it, but the graph x bar is distorted for some odd reason. That code is below:
ggplot(jpycpi, aes(x=jpycpi$DATE, y=jpycpi$JPNCPIALLMINMEI, group=1)) + geom_line()
jpycpi$DATE <- as.Date(as.character(jpycpi$DATE))
fix it? If so, I can explain. – zwolas.Date(as.factor(thing which is a factor))
is the same asas.Date(thing which is a factor)
. I explain why an intermediateas.character
may be necessary in the answer I just wrote. – zwol