-3

I have a data frame with columns like dates, volumes, and companies. I would like to know how to keep only one line for each company?

grep returns the number of lines, but How can I do to get the full line please?

Besides how can I plot these volumes per companies on one single time series plot please?

I found plot.ts but I can't do it while I don't have volumes per companies as if I plot.ts my full data set it does not make the difference between companies and then have a wrong time serie (many points for a single date)

I would like to have a plot like this: time series plot but instead of "websites" have the "volumes" and instead of "shoes,socks,lace" have the name of my companies/subjects

Or like that but with the svolumes time series plot 2

That's how my data looks like:

> head(data)
            Date Time Subject  Sscore  Smean Svscore Sdispersion Svolume  Sbuzz    Last close
1 2015-07-08 09:10:00     MMM -0.2280 0.2593 -0.2795       0.375       8 0.6026 155.430000000
2 2015-07-08 09:10:00     ACE -0.4415 0.3521 -0.0374       0.500       4 0.7200 104.460000000
3 2015-07-07 09:10:00     AES  1.9821 0.0233  1.1743       1.000       1 1.9445  13.200000000
4 2015-07-04 09:10:00     AFL -2.9335 0.0035 -0.2975       1.000       1 0.8321  61.960000000
5 2015-07-07 09:10:00     MMM  0.2977 0.2713 -0.7436       0.400       5 0.4895 155.080000000
6 2015-07-07 09:10:00     ACE -0.2331 0.3519 -0.1118       1.000       3 0.7196 103.330000000
         Company name       Date
1          3M Company 2015-07-08
2         ACE Limited 2015-07-08
3 The AES Corporation 2015-07-07
4          AFLAC Inc. 2015-07-04
5          3M Company 2015-07-07
6         ACE Limited 2015-07-07

Thank you very much!

PavoDive
  • 6,322
  • 2
  • 29
  • 55
Cec Jurczyk
  • 87
  • 1
  • 10
  • 1
    I would suggest you provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and show us what the desired output would look like. This can be a small data.frame with half a dozen rows. – Roman Luštrik Jul 14 '15 at 11:31

2 Answers2

1

I'm not yet totally clear about what you have and what you want. It's very difficult without a reproducible example!

I assume you want to summarize your data by company and date. You could achieve this by using the data.table package:

library(data.table)
setDT(data)
newdata<-data[,.(volume=sum(Svolume)),by=.("Company name",Date)]
# Notice that you can use any other function instead of sum. mean, to mention one

Once you have that newdata object, you can try to plot it with ggplot2:

library(ggplot2)
library(scales)
pl<-ggplot(newdata,aes(x=Date,y=volume,group=`Company name`))+geom_line()+scale_x_date(format="%d-%m-%y")
pl

This solution intends to be general (as your desired output is not well defined in your question), so it might require some minor adjustments.

PavoDive
  • 6,322
  • 2
  • 29
  • 55
0

I found how to do it, if it can help someone else:

library(ggplot2)
ggplot(data)+geom_line(aes(x=data$Date, y=data$Svolume, group=data$Subject, color=data$Subject))
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
Cec Jurczyk
  • 87
  • 1
  • 10