[英]plotting a graph using 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()
將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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.