首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在rPivotTable中绘制多个图表

在rPivotTable中绘制多个图表
EN

Stack Overflow用户
提问于 2019-03-31 01:05:19
回答 1查看 181关注 0票数 0

我想在rPivotTable中绘制多个列。

这是我的数据集。

代码语言:javascript
复制
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

我想使用rPivotTable的折线图来查看销售随促销活动的变化。但我不能同时可视化这两个变量。有什么办法吗?

EN

回答 1

Stack Overflow用户

发布于 2019-04-22 20:56:12

如果将data_plot从宽格式重塑为长格式,则可以在一个图表中绘制这两个变量:

代码语言:javascript
复制
library(data.table)
library(rpivotTable)
rpivotTable(melt(data_plot, id.var = "month"))

对于整形,这里使用data.table中的melt()函数。

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55433760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档