- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试阅读这些帖子的答案来解决我的问题,但没有成功:
Indicating the statistically significant difference in bar graph USING R ,
How to draw the boxplot with significant level? 和
Put stars on ggplot barplots and boxplots - to indicate the level of significance (p-value) 。
我想添加一些线条和标签,以显示使用 R 的分组条形图中的显着性水平,就像红色矩形内的那些。
这是我提出的代码的更简单版本:
#### DATA
g <- as.factor(c('Kit1_A', 'Kit2_A', 'Kit1_B', 'Kit2_B','Kit1_C', 'Kit2_C'))
groups <- rep(g, 3)
targets <- c(rep('X', 6), rep('Y', 6), rep('Z', 6))
mean <- c(20.8, 23.8, 21.61667, 23.54583, 22.26250, 25.41250, 20.39583, 23.82917, 20.70000, 23.82917, 21.52083, 24.83333, 20.68750, 24.60000, 20.78750, 24.42083, 22.86667, 25.28750)
sd <- c(1.249251, 1.137451, 2.372480, 2.439704, 2.149715, 1.465997, 1.579936, 0.944777, 2.320555, 1.419932, 2.636766, 2.820217, 2.014647, 1.384187, 2.193378, 1.685869, 3.456228, 2.197052)
df <-data.frame(groups, targets, mean, sd)
#### Barplot
library(ggplot2)
f <- ggplot(df, aes(x=targets, y=mean, fill=groups))
f <- f + geom_bar(position="dodge", stat="identity", colour='black')
f <- f + geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width=.2,position=position_dodge(.9))
f <- f + theme(legend.title = element_blank())
f <- f + scale_fill_manual(values=c('#D6EAF8','#5DADE2','#2874A6','#D5F5E3','#58D68D','#239B56'))
f <- f + coord_cartesian(ylim = c(0, 35))
最佳答案
也许这不是最好的答案,但你可以用 annotate("rect")
来做。/annotate("segment")
和 grid.text
或者另一个选项是 annotation_custom(grob = linesGrob())
我将您的数据框与 annotate("rect")
一起使用和 grid.text
.
更新后的代码为:
# Add rectangles
f + annotate("rect", xmin = 0.6, xmax = 1.07, ymin = 27, ymax =27, alpha=1,colour = "black")+
annotate("rect", xmin = 0.6, xmax = 0.6, ymin = 26.7, ymax =27, alpha=1, colour = "black")+
annotate("rect", xmin = 1.07, xmax = 1.07, ymin = 26.7, ymax =27, alpha=1, colour = "black")+
annotate("rect", xmin = 0.778, xmax = 1.2, ymin = 29.5, ymax =29.5, alpha=1,colour = "black") +
annotate("rect", xmin = 0.778, xmax = 0.778, ymin = 29.2, ymax =29.5, alpha=1,colour = "black") +
annotate("rect", xmin = 1.2, xmax = 1.2, ymin = 29.2, ymax =29.5, alpha=1,colour = "black") +
annotate("rect", xmin = 0.925, xmax = 1.4, ymin = 32, ymax =32, alpha=1,colour = "black") +
annotate("rect", xmin = 0.925, xmax = 0.925, ymin = 31.5, ymax =32, alpha=1,colour = "black") +
annotate("rect", xmin = 1.4, xmax = 1.4, ymin = 31.5, ymax =32, alpha=1,colour = "black") +
# Second two lines
annotate("rect", xmin = 1.61, xmax = 2.08, ymin = 27, ymax =27, alpha=1,colour = "black")+
annotate("rect", xmin = 1.61, xmax = 1.61, ymin = 26.7, ymax =27, alpha=1, colour = "black")+
annotate("rect", xmin = 2.08, xmax = 2.08, ymin = 26.7, ymax =27, alpha=1, colour = "black")+
annotate("rect", xmin = 1.76, xmax = 2.2, ymin = 29.5, ymax =29.5, alpha=1,colour = "black") +
annotate("rect", xmin = 1.76, xmax = 1.76, ymin = 29.2, ymax =29.5, alpha=1,colour = "black") +
annotate("rect", xmin = 2.2, xmax = 2.2, ymin = 29.2, ymax =29.5, alpha=1,colour = "black")
# Add text
grid.text((paste("p<0.001")),
x = unit(0.15, "npc"), y = unit(0.77, "npc"), just = c("left", "bottom"),
gp = gpar(fontface = "bold", fontsize = 8, col = "black"))
grid.text((paste("p<0.001")),
x = unit(0.185, "npc"), y = unit(0.839, "npc"), just = c("left", "bottom"),
gp = gpar(fontface = "bold", fontsize = 8, col = "black"))
grid.text((paste("p<0.001")),
x = unit(0.233, "npc"), y = unit(0.902, "npc"), just = c("left", "bottom"),
gp = gpar(fontface = "bold", fontsize = 8, col = "black"))
# Second two lines
grid.text((paste("p<0.001")),
x = unit(0.42, "npc"), y = unit(0.77, "npc"), just = c("left", "bottom"),
gp = gpar(fontface = "bold", fontsize = 8, col = "black"))
grid.text((paste("p<0.001")),
x = unit(0.45, "npc"), y = unit(0.839, "npc"), just = c("left", "bottom"),
gp = gpar(fontface = "bold", fontsize = 8, col = "black"))
关于r - ggplot2:如何在分组条形图上添加线条和 p 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37733800/
您好,我正在处理 BIRT 报告。我有一个查询,我必须对父级的重复数据进行分组,但子级也不能分组! 在我的查询中: item 是父项,item_ledger_entry 是子项。我有来自 item.N
我正在使用 GA API。 这是针对 MCF 目标报告(底部)的标准目标完成指标表(顶部) 看一下这个: 总数加起来 (12,238),但看看按 channel 分组的分割有多么不同!我以为这些会很接
我正在开发一个流量计数器,我想获得 IP 和重复计数,但是如何? 就像是 :select ip, count(ip) from Redirect 返回 : null total ip count 重定
我尝试编写一个正则表达式来匹配条件表达式,例如: a!=2 1+2=2+a 我尝试提取运算符。我当前的正则表达式是“.+([!=<>]+).+” 但问题是匹配器总是尝试匹配组中可能的最短字符串
在 MS Transact SQL 中,假设我有一个这样的表(订单): Order Date Order Total Customer # 09/30/2008 8
我想按 m.ID 分组,并对每个 m.id 求和 (pm.amount_construction* prod.anzahl) 实际上我有以下结果: Meterial_id | amount_const
我想根据多列中的值对值进行分组。这是一个例子: 我想得到输出: {{-30,-50,20},{-20,30,60},{-30,NULL or other value, 20}} 我设法到达: SELE
我正在尝试找出运行此查询的最佳方式。我基本上需要返回在我们的系统中只下了一个订单的客户的“登录”字段列表(登录字段基本上是客户 ID/ key )。 我们系统的一些背景...... 客户在同一日期下的
给定以下mysql结果集: id code name importance '1234', 'ID-CS-B', 'Chocolate Sauce'
大家好,我的数据框中有以下列: LC_REF 1 DT 16 2C 2 DT 16 2C 3 DT 16 2C 1 DT 16 3C 6 DT 16 3C 3
我有这样的 mongoDB 集合 { "_id" : "EkKTRrpH4FY9AuRLj", "stage" : 10, }, { "_id" : "EkKTRrpH4FY9
假设我有一组数据对,其中 index 0 是值,index 1 是类型: input = [ ('11013331', 'KAT'), ('9085267',
java中用stream进行去重,排序,分组 一、distinct 1. 八大基本数据类型 List collect = ListUtil.of(1, 2, 3, 1, 2).stream().fil
基本上,我从 TABLE_A 中的这个开始 France - 100 France - 200 France - 300 Mexico - 50 Mexico - 50 Mexico - 56 Pol
我希望这个正则表达式 ([A-Z]+)$ 将选择此示例中的最后一次出现: AB.012.00.022ABC-1 AB.013.00.022AB-1 AB.014.00.022ABAB-1 但我没有匹配
我创建了一个数据透视表,但数据没有组合在一起。 任何人都可以帮助我获得所需的格式吗? 我为获取数据透视表而编写的查询: DECLARE @cols AS NVARCHAR(MAX), -- f
我想按时间段(月,周,日,小时,...)选择计数和分组。例如,我想选择行数并将它们按 24 小时分组。 我的表创建如下。日期是时间戳。 CREATE TABLE MSG ( MSG_ID dec
在 SQL Server 2005 中,我有一个包含如下数据的表: WTN------------Date 555-111-1212 2009-01-01 555-111-1212 2009-
题 假设我有 k 个标量列,如果它们沿着每列彼此在一定距离内,我想对它们进行分组。 假设简单 k 是 2 并且它们是我唯一的列。 pd.DataFrame(list(zip(sorted(choice
问题 在以下数据框中 df : import random import pandas as pd random.seed(999) sz = 50 qty = {'one': 1, 'two': 2
我是一名优秀的程序员,十分优秀!