是否有R包或函数生成Levey-Jennings图表?

use*_*559 1 plot r ggplot2

我在实验室工作,我们必须制作日常的Levey-Jennings图表,我想知道是否有一种简单的方法使用R生成Levey-Jennings图表.

tim*_*ffe 6

好吧,我用谷歌搜索并没有在CRAN上找到一个,但也许Levey-Jennings的图表也有另一个名字?无论如何,这是一个低技术的,你可以根据维基百科上描述进行调整:

# make a data series
my.stat <- rnorm(100,sd=2.5)
# get its standard dev:
my.sd <- sd(my.stat)
# convert series to distance in sd:
my.lj.stat <- (my.stat - mean(my.stat)) / my.sd

plot(1:100, my.lj.stat, type = "o", pch = 19, col = "blue", ylab = "sd", xlab = "observation",
    main = paste("mean value of", round(mean(my.stat),3),"\nstandard deviation of",round(my.sd,3)))

# a low tech L-J chart function:
LJchart <- function(series, ...){
    xbar        <- mean(series)
    se          <- sd(series)
    conv.series <- (my.stat - xbar) / se

    plot(1:length(series), conv.series, type = "o", pch = 19, col = "blue", ylab = "sd", xlab = "observation",
        main = paste("mean value of", round(xbar,3), "\nstandard deviation of", round(se,3)), ...)
}

LJchart(rnorm(100,sd=2.5))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

[编辑:为第一个区域添加阴影区域,灵感来自Seth的评论]

这个也有更灵活的args我猜,但是我不太熟悉使用...不同的函数共享时...,但尝试使用这个例子它不会破坏:

LJchart <- function(series, ...){
    xbar        <- mean(series)
    se          <- sd(series)
    conv.series <- (my.stat - xbar) / se

    plot(1:length(series), conv.series, type = "n", ...)
    rect(0, -1, length(series)+1, 1, col = gray(.9), border = NA)
    lines(1:length(series), conv.series, ...)
    points(1:length(series), conv.series, ...)
    if (! "main" %in% names(list(...))) {
        title(paste("mean value of", round(xbar,3), "\nstandard deviation of", round(se,3)))
    }
}

LJchart(rnorm(100,sd=2.5), xlab = "observations", ylab = "sd", col = "blue", pch = 19)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Pau*_*tra 6

对于绘图,我ggplot2比标准图形更喜欢。因此,这是我使用的解决方案ggplot2

theme_set(theme_bw())

dat = data.frame(value = rnorm(100,sd=2.5))
dat = within(dat, {
    value_scaled = scale(value, scale = sd(value))
    obs_idx = 1:length(value)
  })

ggplot(aes(x = obs_idx, y = value_scaled), data = dat) + 
  geom_ribbon(ymin = -1, ymax = 1, alpha = 0.1) +
  geom_line() + geom_point()
Run Code Online (Sandbox Code Playgroud)

其产量:

在此输入图像描述