Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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
R ggplot2条形图中出现的错误条过低_R_Ggplot2 - Fatal编程技术网

R ggplot2条形图中出现的错误条过低

R ggplot2条形图中出现的错误条过低,r,ggplot2,R,Ggplot2,我们一直在搜索网站(和其他网站)以找到下图所示问题的解决方案。尽管我尝试了很多不同的解决方案来解决我在这里和其他地方遇到的类似问题,但我无法让错误条从“低”位置移动 无论是单独生成一个图形还是将两个图形与gridExtra组合,都会出现问题 以下是包含的每个数据集的代码和示例: 第一个数据集示例: Group PSQI Time_Point 1 Control 2 Baseline 2 Control 2 Baseline 3 Control 2 Bas

我们一直在搜索网站(和其他网站)以找到下图所示问题的解决方案。尽管我尝试了很多不同的解决方案来解决我在这里和其他地方遇到的类似问题,但我无法让错误条从“低”位置移动

无论是单独生成一个图形还是将两个图形与
gridExtra
组合,都会出现问题

以下是包含的每个数据集的代码和示例:

第一个数据集示例:

Group      PSQI Time_Point
1 Control    2   Baseline
2 Control    2   Baseline
3 Control    2   Baseline
4 Control   13   Baseline
5 Control    1   Baseline
6 Control    7   Baseline
第二:

  Group    ESS Time_Point
1 Control   3   Baseline
2 Control   4   Baseline
3 Control   1   Baseline
4 Control   0   Baseline
5 Control   7   Baseline
6 Control  11   Baseline
代码:

库(gridExtra)
图书馆(GG2)
图书馆(网格)

p1最好使用
geom\u errorbar
。首先,您必须创建一个新的
data.frame
,每个小节一行,包括标准错误(我添加了一个“After”时间点以显示其外观):

然后,这个
ggplot
调用将起作用:

ggplot(psqi, aes(fill=Group, y=PSQI, x=Time_Point, ymin=PSQI-StdErr, ymax=PSQI+StdErr)) + #the ymin and ymax parameters here tell it where to put the top and bottom error bars
    geom_bar(stat="identity") +
    geom_errorbar() #you can change the width and thickness of the bars
生成此图像:


最好使用
geom\u errorbar
。首先,您必须创建一个新的
data.frame
,每个小节一行,包括标准错误(我添加了一个“After”时间点以显示其外观):

然后,这个
ggplot
调用将起作用:

ggplot(psqi, aes(fill=Group, y=PSQI, x=Time_Point, ymin=PSQI-StdErr, ymax=PSQI+StdErr)) + #the ymin and ymax parameters here tell it where to put the top and bottom error bars
    geom_bar(stat="identity") +
    geom_errorbar() #you can change the width and thickness of the bars
生成此图像:


欢迎来到SO。请编辑您的问题,并提供一个显示您的问题并准备在新的R会话中复制粘贴运行的示例。如果您计算每个方面的两个级别的平均值,您会注意到错误栏的中心位于平均值所在的位置。欢迎使用此示例。请编辑您的问题,并提供一个显示您的问题并准备在新的R会话中复制粘贴运行的示例。如果您计算每个方面的两个级别的平均值,您会注意到错误栏的中心位于平均值所在的位置。工作得非常好!传奇工作得很好!传奇
ggplot(psqi, aes(fill=Group, y=PSQI, x=Time_Point, ymin=PSQI-StdErr, ymax=PSQI+StdErr)) + #the ymin and ymax parameters here tell it where to put the top and bottom error bars
    geom_bar(stat="identity") +
    geom_errorbar() #you can change the width and thickness of the bars