简体   繁体   English

将第 1/3 个四分位数和第 90 个百分位数添加到 R 中的折线图

[英]Adding 1st/3rd quartile and 90th percentile to a line chart in R

The title says it all.标题说明了一切。 What I would like to do is plotting the median, but also displaying the two quartiles as well as the 90th percentile at each timepoint.我想要做的是绘制中位数,但还要显示每个时间点的两个四分位数以及第 90 个百分位数。

First, here's a small sample dataset with observations y for 3 timepoints time (100 observations for each timepoint).首先,这是一个小样本数据集,其中y为 3 个时间点time (每个时间点 100 个观察值)。

dd <- data.frame(y=c(rnorm(100, 10, 2), rnorm(100, 15, 2), rnorm(100, 20,2)), time=rep(c(1,2,3), each=100)) dd <- data.frame(y=c(rnorm(100, 10, 2), rnorm(100, 15, 2), rnorm(100, 20,2)), time=rep(c(1,2,3) ),每个=100))

Next, summarizing you data according to what you want (here only median and first quantile, but the principle is the same to obtain other quantiles)接下来,根据你想要的来总结你的数据(这里只有中位数和第一个分位数,但获取其他分位数的原理是相同的)

dd1 <- ddply(dd, "time", summarise, med=median(y), firstquart=quantile(y, probs=.01)) dd1 <- ddply(dd, "time", summarise, med=median(y), firstquart=quantile(y, probs=.01))

Finally, plotting your lines with ggplot - first quantile is in red.最后,用ggplot绘制线条 - 第一个分位数为红色。

ggplot(dd1, aes(x=time, y=med)) + geom_line()+geom_line(aes(x=time, y=firstquart), colour="red") ggplot(dd1, aes(x=time, y=med)) + geom_line()+geom_line(aes(x=time, y=firstquart), colour="red")

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅 R 中第 1 和第 3 四分位数之间包含的数据的平均值 - Mean value only of the data contained between the 1st and 3rd quartile in R 如何使用R计算与具有相同字符的另一列对应的一列的第90个百分位数 - How to calculate the 90th percentile of a column corresponding to another column having same characters using R 将平均值、第一和第三四分位数添加到框 plot 和 ggplot2 中的点 plot 的图例中 - Add mean, 1st, and 3rd quartile to the legend of box plot combined with point plot in ggplot2 计算数据框中各列的百分之九十 - Calculate 90th percentile across columns in a data frame R:确定两个不同数据帧的两个文本字符串之间的第一,第二,第三,第四匹配 - R: Identify 1st, 2nd, 3rd, 4th match between two text strings of two different dataframes 来自每日数据的年平均值、最小值、最大值、第 90 个百分位数和第 10 个百分位数 - yearly mean, min, max, 90th percentile, and 10th percentile from daily data 替换第 2 和第 3 个冒号,但在 R 中的字符串中保留第 1 个 - Replacing 2nd and 3rd Colons but Keeping 1st in String in R 使用R中Raster包中的分位数功能计算一叠栅格的第1次和第4​​次方 - Calculation of 1st and 3rd quadrilles for a stack of raster using quantile function in Raster package in R R:如何根据数据框中的前几行为第90个分位数创建新列 - R: How to create a new column for 90th quantile based off previous rows in a data frame R:添加一个较短长度的列,减去单个列中的每一行,第1列 - 第2行,第2行 - 第3行 - R: Add a column of shorter length that subtracts each row in a single column, 1st - 2nd, 2nd - 3rd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM