1

I am trying to resolve an issue I am having with my data in the hope of prooducing a line plot in ggplot2. This is my data (outputted with dput()). It is suppose to be ten rows and two columns, one of date (d,m,y,h,m) and the other one of counts. Apologies for the state of the code, when I try to reproduce the code more simply, it works, and I can't see where the problem is when I try to produce the graph.

day2 <- structure(list(date = structure(c(1355210880, 1355211000, 1355211120, 1355211240, 1355211360, 1355211480, 1355211600, 1355211720, 1355211840, 1355211960), class = c("POSIXct", "POSIXt"), tzone = ""), Counts = c("12", "45", "12", "4", "2", "3", "2", "2", "2", "0")), .Names = c("date", "Counts"), row.names = 4405:4414, class = "data.frame") 

The graph I am trying to plot is:

library(ggplot2) g = ggplot(day2, aes(x=date, y=Counts)) g + geom_line() 

But the resulting graph is simply horizontal lines, and the Counts columns goes up in non consecutive numbers. Can anyone help?

1 Answer 1

2

You have to tell ggplot how to group your points to draw a line:

g + geom_line(aes(group = 1)) 
Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks @joran - I get data now on the graph but the y axis is mixed up (i.e. 0,1,10,100..., 2,21,200... etc). Have you got any recommendations?
@KT_1 The Counts variable in the data you provided in your question is a character variable. You probably want to convert it to numeric via as.numeric.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.