在R GGPLOT2中创建销售报告

发布于 2025-02-01 11:37:57 字数 442 浏览 2 评论 0原文

我想使用ggplot2在R中创建销售报告。 我想要X轴和Y轴的$销售日期,我也想展示我们在整个销售期间进行的促销活动。因此,我们可以确定哪些促销表现良好。我能够通过GEOM_POINT进行操作,并使用Color =促销,但是我的某些促销活动是重叠的,不知道该如何解决。我可以实现这一目标的最好方法是什么。

如果可以帮助我实现此情况,我可以使用任何其他图形(例如栏或直方图)。

这是我使用的代码。

ggplot(data = sales)+
 geom_point(mapping = aes(x = Date, y = Total_Sales, color = Promotions, size = Total_Sales))+ 
 theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

谢谢你!

I want to create sales report in R using ggplot2.
I want dates in x-axis and $ sales in y-axis and I also want to show promotions we did during the whole sale period. So we can Identify which promotions did well. I was able to do it thru geom_point and use color=Promotions but some of my promotions are overlapping and don't know how to tackle that. What is the best way I can achieve this.

I am open to use any other graph like bar or histogram if that can help me achieve this scenario.

Here's the code I use.

ggplot(data = sales)+
 geom_point(mapping = aes(x = Date, y = Total_Sales, color = Promotions, size = Total_Sales))+ 
 theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2025-02-08 11:37:58

通过数据的描述,您似乎有三个变量,datetotal_salespromotions绘制彩色点表示促销的数量可能使很难看到销售/促销之间的关系。您可以制作一个条/线图(包括代码),但这列出了规模问题,促销的数量可以是单位数字,而销售量则为数千个。我只包括了演示如何做的代码,但是这样做不是一个好主意。

最好使用比例(百分比)来查看销售/促销之间的关系。

编辑

由于您的促销变量是离散的,并且您的total_sales不区分促销促销和销售数量。

library(tidyverse)

sales %>% 
  group_by(Date, Total_Orders, Total_Sales) %>% 
  summarise(n_events = n()) %>% 
ggplot(aes(x = factor(Date), y = Total_Sales, fill = n_events)) +
  geom_bar(stat = "identity") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

Going by the description of your data, it seems your have three variables, Date, Total_Sales, and Promotions and plotting colored dots, where the color indicates the amount of promotions, may make it difficult to see the relationship between sales/promotions. You could make a bar/line graph (code included), but this presents the problem of scale, the number of promotions may be single digits, and the amount of sales in the thousands. I just included the code to demonstrate how to do it, but it's not a good idea to do it this way.

It will be better to use proportions (percentages) to see the relationship between sales/promotions.

EDITED

Since your Promotions variable is discrete and your Total_Sales do not distinguish between promotions, then you can count the number of promotions and see the association between number of promotions and sales.

library(tidyverse)

sales %>% 
  group_by(Date, Total_Orders, Total_Sales) %>% 
  summarise(n_events = n()) %>% 
ggplot(aes(x = factor(Date), y = Total_Sales, fill = n_events)) +
  geom_bar(stat = "identity") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文