从直方图中获取值并将其除以第二个直方图中的值

时间:2021-05-16 14:55:00

I would like to add an abline to a histogram which shows the value from the first histogram (data) divided by the value from the second histogram (Survived).

我想在直方图中添加一个abline,它显示第一个直方图(数据)的值除以第二个直方图(Survived)的值。

hist(data$test, col='blue', main="DataPoint", xlim=c(0,600), ylim=c(0,800), breaks=c(seq(0,600,50)))
hist(Survived$test, col='green', breaks=c(seq(0,600,50)), add=TRUE)

Im trying to get something like the below onto the histogram. Any assistance would be appreciated.

我试图在直方图上得到类似下面的内容。任何援助将不胜感激。

abline(count(data$test)/count(Survived$test), breaks = c(seq(0,600,50)), add = TRUE)

1 个解决方案

#1


2  

It is possible to assign the output from hist to an object, like so:

可以将hist的输出分配给对象,如下所示:

> x <- hist(1:10)

> x
$breaks
[1]  0  2  4  6  8 10

$counts
[1] 2 2 2 2 2

$density
[1] 0.1 0.1 0.1 0.1 0.1

$mids
[1] 1 3 5 7 9

$xname
[1] "1:10"

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"

You can then access the values, e.g. with x$density or x$counts.

然后,您可以访问这些值,例如x $密度或x $计数。

#1


2  

It is possible to assign the output from hist to an object, like so:

可以将hist的输出分配给对象,如下所示:

> x <- hist(1:10)

> x
$breaks
[1]  0  2  4  6  8 10

$counts
[1] 2 2 2 2 2

$density
[1] 0.1 0.1 0.1 0.1 0.1

$mids
[1] 1 3 5 7 9

$xname
[1] "1:10"

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"

You can then access the values, e.g. with x$density or x$counts.

然后,您可以访问这些值,例如x $密度或x $计数。