【问题标题】:Errorbars plot too big compared to the bars?与条形图相比,误差线图太大?
【发布时间】:2021-01-23 20:29:11
【问题描述】:

我找不到我的误差条与我的条相比如此大的原因? 非常感谢!

df3
  Amplitudes   QF Detect_Bin        sd
1          3  0.5  0.2118056 0.2909918
2          3    1  0.2037037 0.3012713
3          3 1.25  0.1701389 0.2931458
4          6  0.5  0.5729167 0.4023829
5          6    1  0.4994213 0.4057509
6          6 1.25  0.4085648 0.4043558
7          9  0.5  0.7384259 0.3479116
8          9    1  0.6574074 0.3831921
9          9 1.25  0.5821759 0.4015536
bar<-ggplot(df3, aes(x= Amplitudes, y= Detect_Bin, fill=Amplitudes))
bar+ 
geom_bar(stat="identity")+
geom_errorbar(aes(ymin=Detect_Bin-sd, ymax=Detect_Bin+sd), width = .2, size=0.5)+
facet_wrap(~QF)+
labs(x="Amplitude du SS", y="Moyenne de détection") 

Figure plot

【问题讨论】:

    标签: r ggplot2 errorbar


    【解决方案1】:

    我已经复制了你的情节,代码没有任何问题。您使用ymin=Detect_Bin-sdymax=Detect_Bin+sd 生成误差线。 sd 列的值大于或接近 Detect_bin 中的值。正如您在表格中看到的,这些值是正确的。

    数据

    df3 <- data.frame("Amplitudes" = c(3,3,3,6,6,6,9,9,9), "QF" = c(0.5,1,1.25,0.5,1,1.25,0.5,1,1.25), Detect_Bin = c(0.2118056, 0.2037037, 0.1701389, 0.5729167, 0.4994213, 0.4085648, 0.7384259, 0.6574074, 0.5821759), sd = c(0.2909918, 0.3012713, 0.2931458, 0.4023829, 0.4057509, 0.4043558, 0.3479116, 0.3831921, 0.4015536))
    df3$Amplitudes <- factor(df3$Amplitudes, levels = c("3","6","9"))
    
    
    df3 %>% mutate(ymin = Detect_Bin-sd, ymax= Detect_Bin+sd)
    
    Amplitudes QF Detect_Bin sd ymin ymax
    3 0.50 0.2118056 0.2909918 -0.0791862 0.5027974
    3 1.00 0.2037037 0.3012713 -0.0975676 0.5049750
    3 1.25 0.1701389 0.2931458 -0.1230069 0.4632847
    6 0.50 0.5729167 0.4023829 0.1705338 0.9752996
    6 1.00 0.4994213 0.4057509 0.0936704 0.9051722
    6 1.25 0.4085648 0.4043558 0.0042090 0.8129206
    9 0.50 0.7384259 0.3479116 0.3905143 1.0863375
    9 1.00 0.6574074 0.3831921 0.2742153 1.0405995
    9 1.25 0.5821759 0.4015536 0.1806223 0.9837295

    幅度 3 中的负值对应于零以下的值。从我的角度来看,表示没有错误,也许你不想要那个特定的情节。

    【讨论】:

    • 你是对的!我的代码没问题。事实上我没想到是 sd 采用的值... Detect_Bin 不能为负,所以我很惊讶 ymin
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多