Reputation: 43
I want to plot multiple columns in rPivotTable.
Here is my dataset.
data_plot = data.frame(month = c(1,2,3,1,2,3), SALES = c(47, 90, 23, 75, 19, 28), promotions = c(3,4,2,5,1,2))
rpivotTable(data_plot)
I want to see the variations of Sales with promotions using a line Chart using rPivotTable. But I am not able to simultaneously visualize both the variables. Is there any way?
Upvotes: 0
Views: 251
Reputation: 42544
If data_plot
is reshaped from wide to long format, both variables can be plotted in one chart:
library(data.table)
library(rpivotTable)
rpivotTable(melt(data_plot, id.var = "month"))
For reshaping, the melt()
function from the data.table
is used here.
melt(data_plot, id.var = "month")
month variable value 1 1 SALES 47 2 2 SALES 90 3 3 SALES 23 4 1 SALES 75 5 2 SALES 19 6 3 SALES 28 7 1 promotions 3 8 2 promotions 4 9 3 promotions 2 10 1 promotions 5 11 2 promotions 1 12 3 promotions 2
Upvotes: 1