代码之家  ›  专栏  ›  技术社区  ›  Joe

我的条形图只从我的数据中打印一个条形图

  •  0
  • Joe  · 技术社区  · 4 年前

    当使用以下数据和代码时,my bar char只打印1条,你知道如何解决这个问题吗?

    life_bar
    # A tibble: 6 × 2
      Continent                mn
      <chr>                 <dbl>
    1 Africa                 41.1
    2 Americas               19.5
    3 Eastern Mediterranean  47.0
    4 Europe                 15.6
    5 South-East Asia        37.7
    6 Western Pacific        16.4
    

    使用的代码;

    ggplot(life_bar, aes(x = 'mn')) +
    geom_bar(fill = 'green', col = 'black')
    
    1 回复  |  直到 4 年前
        1
  •  0
  •   neilfws    4 年前

    您需要同时指定这两个选项 x y 变量。 十、 应该是 Continent Y 应该是 mn .你不能引用列名。

    使用时也是如此 geom_bar() 在您的情况下,您需要指定应该如何聚合这些值 geom_bar(stat = "identity") .你可以通过使用 geom_col() .

    ggplot(life_bar, aes(x = Continent, y = mn)) + 
    geom_col()
    

    R中有很多内置的帮助 例如 ?geom_bar extensive online help too .