r - Get matching lines from a character and plot ts -
i have data frame columns dates, volumes, , companies. know how keep 1 line each company?
grep
returns number of lines, how can full line please?
besides how can plot these volumes per companies on 1 single time series plot please?
i found plot.ts can't while don't have volumes per companies if plot.ts full data set not make difference between companies , have wrong time serie (many points single date)
i have plot this: time series plot instead of "websites" have "volumes" , instead of "shoes,socks,lace" have name of companies/subjects
or svolumes time series plot 2
that's how 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 aes corporation 2015-07-07 4 aflac inc. 2015-07-04 5 3m company 2015-07-07 6 ace limited 2015-07-07
thank much!
i'm not yet totally clear have , want. it's difficult without reproducible example!
i assume want summarize data company , date. achieve using data.table
package:
library(data.table) setdt(data) newdata<-data[,.(volume=sum(svolume)),by=.("company name",date)] # notice can use other function instead of sum. mean, mention 1
once have newdata
object, can try plot 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 general (as desired output not defined in question), might require minor adjustments.
Comments
Post a Comment