我想在rPivotTable中绘制多个列。
这是我的数据集。
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)我想使用rPivotTable的折线图来查看销售随促销活动的变化。但我不能同时可视化这两个变量。有什么办法吗?
发布于 2019-04-22 20:56:12
如果将data_plot从宽格式重塑为长格式,则可以在一个图表中绘制这两个变量:
library(data.table)
library(rpivotTable)
rpivotTable(melt(data_plot, id.var = "month"))

对于整形,这里使用data.table中的melt()函数。
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
https://stackoverflow.com/questions/55433760
复制相似问题