如何使用PowerBi中的R中的直方图标记X轴上的每个条形

时间:2022-03-20 13:37:01

I'm using R and PowerBI. I use hist() function for histogram and it does the job. I'm not able to put labels for each bar on x axis. The closes parameter I found is called labels = TRUE

我正在使用R和PowerBI。我使用hist()函数进行直方图,它完成了这项工作。我无法在x轴上为每个条形标记。我发现的closes参数叫做labels = TRUE

如何使用PowerBi中的R中的直方图标记X轴上的每个条形

I want each bar to have a value that is increment of 10,000 in this case.

我希望每个栏的值都增加10,000,在这种情况下。

1 个解决方案

#1


1  

assign the histogram to a variable and then obtain the values to plot and co-ordinates to plot at from that variable. Set xaxt = "n" to supress x-axis at first and then use axis to add the desired x-axis. Read more at ?par

将直方图分配给变量,然后获取要绘制的值,并从该变量绘制坐标。将xaxt =“n”设置为首先抑制x轴,然后使用轴添加所需的x轴。阅读更多信息?

set.seed(42)
x = rnorm(250)
h = hist(x, xaxt = "n")
text(x = h$mids, y = h$counts, labels = h$counts, pos = 3)
axis(side = 1, at = h$mids, seq_along(h$mids)*10000, las = 2)

#1


1  

assign the histogram to a variable and then obtain the values to plot and co-ordinates to plot at from that variable. Set xaxt = "n" to supress x-axis at first and then use axis to add the desired x-axis. Read more at ?par

将直方图分配给变量,然后获取要绘制的值,并从该变量绘制坐标。将xaxt =“n”设置为首先抑制x轴,然后使用轴添加所需的x轴。阅读更多信息?

set.seed(42)
x = rnorm(250)
h = hist(x, xaxt = "n")
text(x = h$mids, y = h$counts, labels = h$counts, pos = 3)
axis(side = 1, at = h$mids, seq_along(h$mids)*10000, las = 2)