I have a dataset like the following one, and I have about 1 million rows like this:
orderid prodid priceperitem date category_eng
3010419 2 62420 18.90 2014-10-09 roll toliet paper
I am currently plotting a plot of these products scatterplots using priceperitem
as y-axis and date
as x-axis. I have also ordered these rows based on these products' coefficient of variation of their prices throughout time. I have summarized these results in another dataset like the following one:
prodid mean count sd cv
424657 12.7124 5541.0000 10.239 80.54999886
158726193 23.7751 1231.0000 17.7567 74.68621596
And I have used the following code to get the scatterplots of many products at the same time:
ggplot(Roll50.last, aes(x=date, y=priceperitem)) + geom_point() + facet_wrap(~prodid)
But I want to order the plots based on these products' CV that I have summarized in another data.frame. I am wondering if there is a way that can allow me to specify that I want to order the panel plots by the order of a value in another dataframe.
Below is a small sample data. Basically, the idea is to get the different products' price cv which = s.d./mean. And I want to plot these scatterplot of these products in order of cv from highest to lowest.
#generate reproducible example
id = c(1: 3)
date = seq(as.Date("2011-3-1"), as.Date("2011-6-8"), by="days")
id = rep(c(1,2,3,4),each=25)
set.seed(01)
id = sample(id)
price = rep(c(1:20), each = 5)
price = sample(price)
data = data.frame(date, id, price)