简体   繁体   中英

plotting multiple charts in rPivotTable

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)

see here for pivot Table 1

see here for pivot Table 2

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?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM