0
      Days     Profit
4672 5195  79823.72824
4673 5196  79823.72824
4674 5197  79823.72824
4675 5198  79823.72824
4676 5199  79823.72824
4677 5200  79823.72824
4678 5201  79823.72824
4679 5203  77760.56168
4680 5204  77760.56168
4681 5205  77760.56168
4682 5206  77760.56168
4683 5207  77760.56168
4684 5212  85379.47144
4685 5213  85379.47144
4686 5214  85379.47144
4687 5215  85379.47144
4688 5216  85379.47144

Above is an example of the data frame that I created, I only posted a small chunk of it as it is around 7000 rows. I am trying to create a line graph with the data using ggplot. The graphs that I see others post look very nice and professional but when I created mine it was not. Below you will see how I used ggplot and my graph result.

 df <- data.frame(Days = Day_value, Profit = PnL_value)
 p <- ggplot(data=df, aes(x=Days, y=Profit)) + geom_line() + geom_point()

ggplot results

The graph below is the print of my entire data set and not just the select data I shared. One thing to notice is that my Days column does not always increment by 1.

I would ideally have my graph look like this one with only 1 line instead of 3. Ideal Graph

When I check the Structure I get:

'data.frame':   6993 obs. of  2 variables:
 $ Days  : Factor w/ 6993 levels "100","1000","1001",..: 4180 4286 4397 4489 4598 4699 4810 4910 5008 5111 ...
 $ Profit: num  0 0 0 0 0 0 0 0 0 0 ...
NULL

When I run it I also get this error:

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
Community
  • 1
  • 1
LBD
  • 53
  • 4
  • 1
    check the class "Days". I suspect it's a character. do `str(df)` to get the structure of your data.frame. change the days to integer using as.integer. And to prevent this happening in the future, when you read the data in use stringsAsFactors = FALSE in your read.table call – infominer Apr 27 '15 at 17:51
  • Please could you make a reproducible example and perhaps link to some of the graphs you are trying to emulate? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – r.bot Apr 27 '15 at 19:37
  • @infominer I updated my question to include what you recommended. I am unsure where I should input as.integer() and stringsAsFactors = FALSE – LBD Apr 27 '15 at 20:35
  • Try `ggplot(data=df, aes(x=as.numeric(Days), y=Profit)) + geom_line() + geom_point()` – Alex Apr 27 '15 at 22:39

0 Answers0