为什么 geom_box 绘图栏没有以正确的小数字升序显示

why geom_box plot bar does not appear in corect asending order for small numbers

我正在使用 geom_bar 函数使用以下示例创建条形图。 面积较小的值(例如 0.006 和 0.003)的颜色条不会按升序显示,而是在图表中显示较高的值。 有人知道为什么会发生以及如何解决吗? 谢谢

library(ggplot2)
ID        <-  c(1,1,2,2,3,3)
Type      <-  c("Bc", "Ea", "Ea","Ra", "Lr","Ram")
Area      <- c(0.15,0.11, 0.0066,0.11,0.0037,0.088)
data.Table <- data.frame(ID ,Type,Area )
p         <- ggplot(dataTable)+ 
         geom_bar(aes(fill=Type, y=Area, x=ID), stat="identity")
print(p)

要按区域按升序对堆叠条重新排序,您可以使用 reorder(Type,-Area):

library(ggplot2)
ID        <-  c(1,1,2,2,3,3)
Type      <-  c("Bc", "Ea", "Ea","Ra", "Lr","Ram")
Area      <- c(0.15,0.11, 0.0066,0.11,0.0037,0.088)
data.Table <- data.frame(ID ,Type,Area )

p         <- ggplot(data.Table)+ 
  geom_bar(aes(fill=reorder(Type, -Area), y=Area, x=ID), stat="identity")
print(p)

EDIT 如果 y-axis 应该显示每个条形图的面积值,即条形图不应堆叠在一起,但 addtionally 条形图should not be dodged 那么我能想到的唯一选择是使用 position="identity" (或者 position = position_dodge(width = .1) 来叠加条形图,它混合了躲避和叠加)。在那种情况下,我们必须对数据集进行排序,使得具有小面积的观察结果位于末尾(每个 ID),这可以通过 data.Table[order(ID, -Area),] 来实现。此外,在那种情况下,我们不必重新排序 Type:

library(ggplot2)

ID        <-  c(1,1,2,2,3,3)
Type      <-  c("Bc", "Ea", "Ea","Ra", "Lr","Ram")
Area      <- c(0.15,0.11, 0.0066,0.11,0.0037,0.088)
data.Table <- data.frame(ID ,Type,Area )

data.Table01<- data.Table[order(ID, -Area),]
ggplot(data.Table01) + 
  geom_bar(aes(fill=Type, y=Area, x=ID), stat="identity", position = "identity")