r - 使用 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()
推荐阅读
- python - Python中二维矩阵的傅里叶变换
- flutter - Flutter:升级到新应用版本后显示更改日志/发布说明/“新增功能”
- c# - C# MVC 发送邮件问题
- css - 超出容器最大高度和宽度的文本
- amazon-web-services - 有没有办法通过詹金斯要求部署?
- react-native - React-Native:是否可以获取 FlatList 的布局位置
- jquery - 安装 SSL 证书后,JQuery 矢量地图停止工作。为什么?
- postgresql - `psql` 命令查看所有现有的表空间?
- angular - 检查角度8中的条件后如何重定向到另一个组件?
- vsto - C# 加载项 (VSTO .NET):将域名添加到 Outlook 垃圾邮件列表