0

This code generates what it supposed to be.

ggplot(df,aes(x=df$month,y=df$fuel_swiperate,color=trans_card_type,group=trans_card_type)) + 
  geom_point() +
  geom_line() 

enter image description here

Since I have each category to be on a different facet, I am adding the facet_grid option, but the data is becoming very weird after that as the data are in the wrong facet.

ggplot(df,aes(x=df$month,y=df$fuel_swiperate,color=trans_card_type,group=trans_card_type)) + 
  geom_point() +
  geom_line() +
  facet_grid(~trans_card_type)

enter image description here

Haboryme
  • 4,611
  • 2
  • 18
  • 21
Patrick
  • 1
  • 1
  • It's difficult to diagnose without reproducible data, but did you try with removing the argument `group=trans_card_type`? – Phil Feb 08 '17 at 17:04
  • @Phil thanks for your response. The dataset only has two columns: 1.trans_card_type (three categories) 2.month(1-12) 3.fuel_swiperate (the value) also yea I tried. the points were not in the right facets still. – Patrick Feb 08 '17 at 17:12
  • What I was asking is, did you try with the following code: `ggplot(df,aes(x=df$month,y=df$fuel_swiperate,color=trans_card_type)) + geom_point() + geom_line() + facet_grid(~trans_card_type)` – Phil Feb 08 '17 at 17:17
  • i did. the points were not in the right facets still. and without grouping, ggplot is not able to draw the lines. – Patrick Feb 08 '17 at 17:20
  • Could you provide a sample of `df` and the output of `str(df)`? As I said, it's difficult to determine the issue without looking at how the data is organized. – Phil Feb 08 '17 at 17:27
  • don't use `$` in `aes`. – erc Feb 08 '17 at 17:28
  • You have used `facet_grid(~trans_card_type)` with a one-sided formula. Please, try either `facet_wrap(~trans_card_type)` or `facet_grid(. ~ trans_card_type)`. See `?facet_wrap` and `?facet_grid` for details. – Uwe Feb 08 '17 at 18:25

0 Answers0