1

Using ggplot function, it is possible to group/color the column of interest and plot the data based on that as follows:

ggplot(inputDataFrame, aes(as.numeric(interestingColumn) , group = AnotherColumn)) +
coord_cartesian(xlim = c(0,400)) + geom_line(stat='ecdf')

How can I also add the curve/plot regarding the whole data in "interestingColumn" regardless of the "group" criteria. So that I can compare the whole data and its subdivision groups in one plot.

For instance, running the above code, I will get the figure as follows and I will get the cumulative values for each product separately. How can I add a plot to the following plot which shows the whole products consumption regardless of the product group. enter image description here

Thanks.

user30314
  • 183
  • 1
  • 11
  • Sorry, I don't understand the question. Please produce a [reproducble example](http://stackoverflow.com/a/5963610/1412059) and maybe a mock-up of the expected output. – Roland Dec 04 '14 at 12:22
  • @Roland, sorry but is it clear now? The data is huge and I need to transfer it from the central cluster which I do not have access at the moment. I think I need to add this plot to the above plot: ggplot(inputDataFrame, aes(as.numeric(interestingColumn)) + coord_cartesian(xlim = c(0,400)) + geom_line(stat='ecdf'). I mean without grouping. – user30314 Dec 04 '14 at 12:38
  • @user30314, Did you even bother to read the link Roland posted? – Henrik Dec 04 '14 at 12:41
  • 1
    on the new aestethic, which you don't want to be grouped, use `group = NULL` – zelite Dec 04 '14 at 13:01

1 Answers1

1

You can add a geom_line without the color aesthetics and a geom_line with the color aesthetics. Also see below how to create a reproducible example.

# create your reproducible example...
set.seed(1)
inputDataFrame <- data.frame(interestingColumn = rnorm(100, 200, 80), 
                             AnotherColumn = factor(rbinom(100, 4, .3)))
# plotting
ggplot(inputDataFrame, aes(as.numeric(interestingColumn))) +
  coord_cartesian(xlim = c(0,400)) + 
  geom_line(stat='ecdf') + 
  geom_line(aes(color=AnotherColumn), stat='ecdf')
shadow
  • 21,823
  • 4
  • 63
  • 77