I'm trying to plot several cities' housing prices against time using ggplot
(line chart).
I melted the data so that it looks like:
Dates variable value
2010-01-01 Shanghai 20435
2010-02-01 Shanghai 20782
... Shanghai ...
2018-07-01 Shanghai 22491
2010-01-01 Hangzhou 18827
... Hangzhou ...
2018-07-01 Hangzhou 29255
... ... ...
My code is as follows:
library(ggplot2)
library(scales)
library(reshape2)
Housingpriceslong <- melt(Housingprices, id=c("Dates"))
ggplot(Housingpriceslong, aes(x=Dates, y=value, colour=Housingpriceslong$variable)) +
geom_line() +
scale_x_date(labels = date_format("%Y-%m"), breaks = date_breaks("6 months"))
My questions are:
- Something seems to be wrong and I don't get a proper graph, could you please help me correct my code?
- The
scale_x_date
function does nothing either, my x-axis scale is still shown yearly.