我正在尝试使用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()
答案 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()