1

I am trying to plot a simple time series using ggplot() or qplot(). The horizontal axis will be the date and the vertical axis a number, a simple line chart will suffice. Normally, one would need to melt the rectangle data before using ggplot(). However, I am stuck with this:

net.t <- structure(c(6, 11, 0, -1, -13), .Names = c("2011-09-01", "2011-12-01", 
"2012-03-01", "2012-06-01", "2012-09-01"))

net.t.m <- melt(net.t,id="var")

#After melting 'net.t', it became a vector or array? how to plot that?

qplot(net.t.m,main="Net Promotion Score")+geom_smooth(se=F, size=1.5)
nps.t+labs(y="NPS",x="Year Quarter")+geom_text(aes(label =value),size = 3, vjust = -1)

1 Answer 1

2

Your net.t is just a vector and once you melt it, you have a data frame with only one column. The dates are the names of the rows, not the entries. One solution is to add a column of dates:

net.t.m$date <- as.Date(rownames(net.t.m))
ggplot(net.t.m, aes(x=date, y=value)) + geom_point() +
   geom_smooth(method="loess", se=F, size=1.5) +
   labs(y="NPS",x="Year Quarter") +
   geom_text(aes(label =value),size = 3, vjust = -1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.