我的R条图并未显示出年度销售的差异

发布于 2025-01-25 22:00:47 字数 897 浏览 1 评论 0原文

成功运行条形图后,我有一个问题,其中y轴上的数字在代码中而不是完整,而不是显示正常的数字,而是显示了诸如0E+00之类的代码。

我希望Y轴显示102,000至106,000。

条形图也有不同的数字。但这并没有清楚地显示出年度销售额的差异。

# Table of average total sales by year
yearly_sales <- DataSet %>% group_by(Year) %>% summarise(sales = mean(Weekly_Sales))
summarise(yearly_sales)
mycols <- c("#FF7F50", "#DE3163", "#6495ED")

# Bar chart for Average Yearly Sales 2010 to 2012
barplot(height = yearly_sales$sales, names = yearly_sales$Year, col = mycols)

栏图在此处显示。

我如何获取图表以清楚地显示销售的差异,以及如何获得实际值而不是0E+00

After successfully running my bar plot, I have a PROBLEM where the numbers on the y axis are in codes and not in full, and instead of showing normal figures, it shows codes like 0e+00.

I would like the Y axis to show between 102,000 and 106,000.

The bar plot also has different figures. But it is not showing clearly the difference in yearly sales.

# Table of average total sales by year
yearly_sales <- DataSet %>% group_by(Year) %>% summarise(sales = mean(Weekly_Sales))
summarise(yearly_sales)
mycols <- c("#FF7F50", "#DE3163", "#6495ED")

# Bar chart for Average Yearly Sales 2010 to 2012
barplot(height = yearly_sales$sales, names = yearly_sales$Year, col = mycols)

This is the table I am trying to visualize

The bar plot is shown here.
enter image description here

How can I get the chart to show clearly the difference in sales and how can I get the actual values too instead of 0e+00

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

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

发布评论

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

评论(2

尘曦 2025-02-01 22:00:47

这可以使用YLIMXPD来完成,尽管我以这种方式警告表示您的数据,因为它夸大了年份之间的真正差异,并且通常违反了数据可视化。您在问题中代表的数字更准确。

无论如何,如果您想执行此操作:

# Example data
data <- c(1033660, 1046239, 1059670)

# Plot, `a` saves the position of the x axis to place years text
a <- barplot(data, ylim = c(1020000, 1060000), xpd = FALSE, col = c("#FF7F50", "#DE3163", "#6495ED"))
axis(1, at = a, labels = c(2010, 2011, 2012), tick = FALSE)

ylim设置了限制,XPD在下轴处夹住悬垂。

This can be done using ylim and xpd, though I caution representing your data this way as it exaggerates the true difference between years and is a general violation of data visualization. The figure you represented in your question is more accurate.

At any rate, if you wanted to do this:

# Example data
data <- c(1033660, 1046239, 1059670)

# Plot, `a` saves the position of the x axis to place years text
a <- barplot(data, ylim = c(1020000, 1060000), xpd = FALSE, col = c("#FF7F50", "#DE3163", "#6495ED"))
axis(1, at = a, labels = c(2010, 2011, 2012), tick = FALSE)

ylim sets the limits and xpd clips the overhang at the lower axis.

enter image description here

东走西顾 2025-02-01 22:00:47

暂时禁用科学符号

op <- options(scipen=999)  ## set par
barplot(sales ~ Year, Yearly_sales, col=2:4)
par(op)  ## restore old par

form> form> formatc in。

barplot(sales ~ Year, data=Yearly_sales, col=2:4, yaxt='n')
axis(side=2, at=axTicks(2), labels=formatC(axTicks(2), format='fg'))

就像人们如何在实际上很小的同时给他们统计数据,并给人留下巨大差异的印象,从而欺骗他们的读者。 请不要这样做

与2010年的首次测量相比,显示差异的百分比可能更专业

Yearly_sales <- transform(Yearly_sales, 
                          diff=(sales - sales[Year == 2010])/sales[Year == 2010])

barplot(diff ~ Year, Yearly_sales, col=2:4, yaxt='n', ylim=c(-.04, 0))
axis(side=2, at=axTicks(2), labels=paste0(axTicks(2)*100, '%'))

。 “ https://i.sstatic.net/d2c2a.png” alt =“在此处输入图像说明”>


data:

Yearly_sales <- structure(list(sales = c(1033660, 1046239, 1059670), Year = 2012:2010, 
    diff = c(-0.0245453773344532, -0.0126747006143422, 0)), class = "data.frame", row.names = c(NA, 
-3L))

Either temporally disabling scientific notation ,

op <- options(scipen=999)  ## set par
barplot(sales ~ Year, Yearly_sales, col=2:4)
par(op)  ## restore old par

or formatCing.

barplot(sales ~ Year, data=Yearly_sales, col=2:4, yaxt='n')
axis(side=2, at=axTicks(2), labels=formatC(axTicks(2), format='fg'))

Just like @jpsmith I'm neither a fan of narrowing the x-axis, because that's exactly how folks pimp their statistics and give the impression of huge differences while they are actually tiny, thus deceiving their readers. Please don't do this.

It might be more professional to show the percentage differences, e.g. compared to the first measurement in 2010.

Yearly_sales <- transform(Yearly_sales, 
                          diff=(sales - sales[Year == 2010])/sales[Year == 2010])

barplot(diff ~ Year, Yearly_sales, col=2:4, yaxt='n', ylim=c(-.04, 0))
axis(side=2, at=axTicks(2), labels=paste0(axTicks(2)*100, '%'))

enter image description here


Data:

Yearly_sales <- structure(list(sales = c(1033660, 1046239, 1059670), Year = 2012:2010, 
    diff = c(-0.0245453773344532, -0.0126747006143422, 0)), class = "data.frame", row.names = c(NA, 
-3L))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文