- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用帕累托图(库qcc
):
## abcd is a data frame, and I am producing chart for column products
Product <- abcd$products
names(Product)<-abcd$customerid
pareto.chart(Product, ylab = "Number of Products", xlab="Customer", xaxt="n")
abline(v = 1000)
由于我的数据很大,我想在 x 轴 10% 的间隔后添加 abline
,但不知何故我没有得到线条。
请告诉我某些函数是否可以在这里工作或者在帕累托中不允许abline
?
最佳答案
帕累托图和条形图
pareto.chart()
是基于 barplot()
的,因此只要知道如何将 abline()
添加到 barplot()
,您知道如何使用 pareto.chart()
。为了证明它们的关系,请考虑以下事项:
## example from ?pareto.chart
defect <- c(80, 27, 66, 94, 33)
names(defect) <- c("price code", "schedule date", "supplier code", "contact num.", "part num.")
y <- pareto.chart(defect, ylab = "Error frequency")
barplot(0.2 * defect, add = TRUE, col = "grey")
现在您可以看到条形图重合了。
酒吧在哪里?
pareto.chart() 不返回这些柱的位置是一个陷阱。之前我们将 pareto.chart()
的结果保存在 y
中,现在这就是 y
的全部内容:
> str(y)
num [1:5, 1:4] 94 80 66 33 27 94 174 240 273 300 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:5] "contact num." "price code" "supplier code" "part num." ...
..$ Pareto chart analysis for defect: chr [1:4] "Frequency" "Cum.Freq." "Percentage" "Cum.Percent."
这就是要打印的全部内容:
> y
Pareto chart analysis for defect
Frequency Cum.Freq. Percentage Cum.Percent.
contact num. 94 94 31.33333 31.33333
price code 80 174 26.66667 58.00000
supplier code 66 240 22.00000 80.00000
part num. 33 273 11.00000 91.00000
schedule date 27 300 9.00000 100.00000
这样,我们必须调用 barplot()
才能获取柱形位置:
x <- as.numeric(barplot(defect, plot = FALSE))
# > x
# [1] 0.7 1.9 3.1 4.3 5.5
现在,如果我们在这些位置上执行 abline()
:
pareto.chart(defect, ylab = "Error frequency")
abline(v = x, col = 2) ## red
每 0.1 分位数添加 abline()/segments()
我建议使用:
x <- range(as.numeric(barplot(Product, plot = FALSE)))
x0 <- seq(x[1], x[2], length = 11) ## 11 break points for 10 intervals
y <- pareto.chart(Product, ylab = "Number of Products", xlab="Customer", xaxt="n")[, 2]
y0 <- y[round(seq(from = 1, to = length(y), length = 11))]
## abline(v = v0, col = "purple")
segments(x0, rep(0, 11), x0, y0, col = "purple")
作为演示,我使用
set.seed(0); Product <- rbinom(100, 20, 0.3)
关于r - 如何将 abline() 添加到 pareto.chart()/barplot()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915779/
简单的barplot,其值位于条形顶部(我知道这很愚蠢 - 我被迫添加它们:))。 text 效果很好,但最高频率条上方的值被隐藏。我尝试了边距,但它移动了整个图,而不仅仅是图形区域。你有什么建议?谢
我有一个数据框,其中一个变量(我们称之为 Q1)有几个级别:“无用”、“30 分钟”、“1 小时”、“2 小时”、“3+ 小时”。 如何绘制 barplot(),其中条形按因子水平的顺序排列?我尝试使
我试图在图中展示较差的设计选择。人们使用的一种浪费墨水、可能分散注意力的效果是条形的阴影效果。我想让ggplot2做到这一点。我的基本想法是使第一个半透明的条形层稍高并向右移动。我可以得到稍高一点的位
我在 R 中有一个数据框。每个数据框内有 8 个变量。 我想制作一个条形图,其中我想根据一个特定变量中的值为条形分配不同的灰色阴影。 这就是我制作条形图的方式: barplot(x$cov, name
我尝试创建一个条形图,它同时使用和堆叠。我有一些类似于我想要的方面的东西: tmp <- morley tmp$loc <- paste("No", tmp$Run %/% 2, sep="") tm
我有一个 Pandas 数据框,其中有几个组列,如下所示。 gr1 grp2 variables lb m ub A A1 V1 1.00 1.50
我已将 CSV 文件导入到数据框中并创建了数据透视表: Amount Date 2018-09-30 222 2018-10-01 1
我有以下数据集: words = ['upvoted', 'upvote', 'f***', 'reimer', 'feminists', 'censorship', 'wet', '0
我以前从未见过这个,但是我正在制作的 seaborn barplot 不会均匀地间隔条形...... 代码 fig, ax = plt.subplots(figsize=(25,6)) sns.bar
我有一个条形图,在 X 轴上有类别并在 Y 上计数。有没有办法按 Y 值的降序对条形图进行排序? 这是示例代码 Animals <- c("giraffes", "orangutans", "monk
我正在 ggplot2 中制作一个躲避条形图,一个分组的计数为零,我想显示。我记得在 HERE 上看到过这个前阵子想通了 scale_x_discrete(drop=F)会工作。它似乎不适用于躲避条。
我在使用 Dimple.JS 时遇到问题,他们的分组/顺序规则方法不允许我按照我的意愿控制条形列的顺序或对齐方式。 即使 x 轴顺序已关闭,我也必须在数据中添加名为“顺序”的行,以确保图表的 x 轴按
我想要实现的目标与此处已经提出的完全相同(特别是使用 R 的基本图形,而不是像 ggplot 或lattice 这样的包):Ordering bars in barplot() 但是,那里提出的解决方
我正在尝试实现这样的分布图 对于每个时期,我需要绘制“堆积比例”图表。 数据基本上是这样的: 400 401 402 403 404 ... 1013662 7 7 7
我正在使用 matplotlib 为我的论文创建图表。我正在使用以下代码: import numpy as np import numpy as np import matplotlib as mpl
我用 D3 画了一个条形图。我希望 x 轴值位于底部,y 值位于其本身的条形图上。 由于某种奇怪的原因,标签没有显示。 任何人都可以看一下this fiddle,我将不胜感激. 最后的相关部分 //
我有一本看起来像这样的字典 d = { 'a' : {'L1':2, 'L2':5, 'L3':8}, 'b' : {'L1':4, 'L2':7, 'L3':10}, 'c'
我正在尝试在 Matplotlib 中以对数刻度绘制条形图。如果我手动执行此操作(下图 3),我会得到正确的答案,但如果我使用 matplotlib 的 set_yscale('log') 或使用条形
我正在尝试按组显示相对百分比以及 sns 条形图中的总频率。我比较的两组在大小上有很大不同,这就是为什么我在下面的函数中按组显示百分比。 这是我创建的示例数据框的语法,它在目标分类变量(“项目”)中具
我在条形图中处理概率数据。条形图看起来不错,但是当我尝试添加错误栏时,它们没有组织或绑定(bind)到适当的列。如果我不必手动执行此操作,那就太完美了。 (此示例仅显示了一个子集。) 你能帮我弄清楚如
我是一名优秀的程序员,十分优秀!