Create line graph with ggplot2, using time periods as x-variable

ggplot2, graph, line, r

Solution

You should add `group=1` in your `aes()` call to conect points with line. This will inform `geom_line()` that all your points belong to one level and they should be connected.

ggplot(data=glomor, aes(x=as.character(Period),y=Value,group=1))+
   geom_point()+ylim(0,10) + geom_line()

Problem

I am very new to R, and so this question is extremely elementary, but I can't solve it myself. I would very much appreciate your help. This is a sort of dataframe I want to use: ``` Period Value Cut.off 1 January 1998 - August 2002 8.798129 1.64 2 September 2002 - Jun 2006 4.267268 1.64 3 Jul 2006 - Dec 2009 7.280275 1.64 ``` This the code I am using: ``` require(ggplot2) bq <- ggplot(data=glomor, aes(x=as.character(Period),y=Value))+geom_point()+ylim(0,10) bq <- bq + scale_x_discrete(limits=c("January 1998 - August 2002","September 2002 - Jun 2006","Jul 2006 - Dec 2009")) bq + geom_line() ``` I receive the following error message: ``` geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? ``` How do I need to change the code, so that the points will be connected by a line?

Original source