使用R绘制图形

时间:2018-10-28 17:12:11

标签: r

我正在尝试使用R在下面的数据表的形状和均值之间绘制条形图 现在我的问题是如何绘制条形图。我尝试了一下,但是没有用

    (shp <- tibble(Type   = c("1", "2", "3", "4"),  shapes    = c("square", "rectangle", "rectangle", "square"),  in_num = c(500, 800, 900, 1200),  complete = c(4, 9, 3, 8)
))
    shp %>% group_by(shapes) %>% summarise(Avg = mean(complete))
    ggplot(data = shp, mapping = aes(x = shapes, y = Avg)) +geom_bar()

1 个答案:

答案 0 :(得分:0)

stat = "identity"添加到您的geom_bar()中。并在summarise命令后加上右括​​号。

 shp %>% 
  group_by(shapes) %>% 
  summarise(Avg = mean(complete)) %>%
  ggplot(aes(x = shapes, y = Avg, fill = shapes)) +
  geom_bar(stat = "identity", show.legend = F) +
  theme_bw()