ggplot2 - 当ymin!= 0时,堆栈没有很好地定义

wes*_*oth 0 r ggplot2

在绘制以下数据集时,我得到了一些奇怪的结果,并希望有人可以指出这个问题.我正在尝试使用我的数据进行小平面包装,但似乎结果并非真实.

这是我的数据集 type.mean.prod.rev

Group.1,            Group.2,           x
Prod1,         Expired,  0.339658789
Prod2,         Expired,  0.450215264
Prod3,         Expired,  0.597100606
Prod4,         Expired,  0.450625850
Prod1,   Expiring In 2013,  0.277917631
Prod2,   Expiring In 2013,  0.122023392
Prod3,   Expiring In 2013,  0.011988620
Prod4,   Expiring In 2013,  0.145343114
Prod1,   Expiring In 2014,  0.386366264
Prod2,   Expiring In 2014,  0.402404085
Prod3,   Expiring In 2014,  0.257194254
Prod4,   Expiring In 2014,  0.396879507
Prod1, Expiring Post 2015, -0.003942683
Prod2, Expiring Post 2015,  0.025357259
Prod3, Expiring Post 2015,  0.133716520
Prod4, Expiring Post 2015,  0.007151529
Run Code Online (Sandbox Code Playgroud)

这是我的策划尝试

type.mean.prod.rev.bar <- ggplot(type.mean.prod.rev, 
                             aes(x = type.mean.prod.rev$Group.2,
                                 y = type.mean.prod.rev$x)) + 
  geom_bar(bindwidth = 2,
       stat = "identity") + 
  coord_flip() +
  facet_wrap( ~ Group.1, ncol = 4) +
  theme(axis.title.y = element_blank(),
    axis.title.x = element_blank(),
    panel.border = element_rect(color = "black", fill=NA),
    strip.text = element_text(vjust=.7, 
                               colour="white", 
                               face="bold", 
                               size = rel(1.2)),
    strip.background = element_rect(fill = rgb(red=25,
                                               green = 187,
                                               blue = 222, 
                                               maxColorValue = 255),
                                    colour = "black",
                                    size = 1)) + ylab(NULL) + xlab(NULL)


type.mean.prod.rev.bar                               
Run Code Online (Sandbox Code Playgroud)

我的输出问题是Group.2每个面板中没有表示每个级别,而是每个级别只在一个面板中,几乎就像facet是纯粹的美学并且数据集仍被视为整体(Group.1by x).我知道有一个负数x,这可能会导致麻烦...但即使我将此值重置为零,type.mean.prod.rev[13, 3] <- 0我得到相同的结果.有谁知道为什么输出关闭?

Jus*_*tin 5

当你在里面aes使用时只是列名而不是$ 语法: ggplot(type.mean.prod.rev, aes(x=Group.2, y=x)) + ....