Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
始终着色addtable2plot-plotrix中的行_R_Plot_Plotrix - Fatal编程技术网

始终着色addtable2plot-plotrix中的行

始终着色addtable2plot-plotrix中的行,r,plot,plotrix,R,Plot,Plotrix,我经常从模拟数据中生成直方图,并发现为数据附加一个相关的十分位数表非常有用。我一直在使用plotrix中的addtable2plot函数来执行此操作。我还发现突出显示表中包含50%值的行很有用-以下是一个示例: library(plotrix) # Generate data mu <- -1.771957 sd <- 0.4716474 foo <- rlnorm(100000, mu, sd) # Generate decile table xmax <- .

我经常从模拟数据中生成直方图,并发现为数据附加一个相关的十分位数表非常有用。我一直在使用plotrix中的addtable2plot函数来执行此操作。我还发现突出显示表中包含50%值的行很有用-以下是一个示例:

library(plotrix)

# Generate data

mu <- -1.771957
sd <- 0.4716474

foo <- rlnorm(100000, mu, sd)

# Generate decile table
xmax <- .75

max <- format(xmax, digits=2, nsmall=2)

dc <- quantile(foo, probs=seq(0, 1, 0.1))
dps <- c("100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%", "0%")
dc <- format(round(dc, digits=2), nsmall=2)

decile <- as.data.frame(dps)
deciles <- as.data.frame(cbind(dps,dc), row.names=FALSE)
colnames(deciles) <- c("Probability", "Rate")
deciles$"Rate" <- as.character(deciles$"Rate")
deciles[1,2] <- "0.00"
deciles[11,2] <- paste(">", max, sep="")

# create a plot
hist(foo, freq=F, xlim=c(0,xmax), breaks=50, col="blue")
top <- max(axis(2))
rect(xleft=(.69*xmax), xright=(1.04*xmax), ybottom=(.615*top), ytop=(.665*top), col="gray91", border=NA)
addtable2plot(x=(1.04*xmax), y=(top), xjust=1, yjust=0, table=deciles, cex=0.82,
          title="Title", hlines=TRUE, vlines=TRUE, bty="o", lwd=1.5, bg="transparent")
库(plotrix)
#生成数据

mu你的意思是像这样,也许:

bg_col <- matrix("white",nrow(deciles),ncol(deciles))
bg_col[11,] <- "grey"

# create a plot
hist(foo, freq=F, xlim=c(0,xmax), breaks=50, col="blue")
top <- max(axis(2))
rect(xleft=(.69*xmax), xright=(1.04*xmax), ybottom=(.615*top), ytop=(.665*top), col="gray91", border=NA)
addtable2plot(x=(1.04*xmax), y=(top), xjust=1, yjust=0, table=deciles, cex=0.82,
          title="Title", hlines=TRUE, vlines=TRUE, bty="o", lwd=1.5, bg= bg_col)

bg\u col刚刚意识到我有一个更老版本的plotrix-boy,我觉得自己很傻。