r - R order geom_bar 基于一个级别
问题描述
如何根据变量的第一级订购条形图var
?现在订单是两个条的总和,我希望它只按value
where var
is排序"first"
。下面是一个工作示例。
library("ggplot2")
ct <- rep(c("A", "B", "C", "D"), 2)
var <- c("first","first","first","first","second","second","second","second")
value <- c(1,5,0.5,8,2,11,0.2,0.1)
df <- data.frame(ct, var, value)
df
ggplot() +
geom_bar(data = df
, aes(x = reorder(ct, value)
, y = value
, fill = var
)
, stat = "identity"
, position = "dodge"
, width = .90 )
解决方案
推荐阅读
- html - 您如何在引导程序中将文本居中放置在卡片内?
- javascript - 如何创建显示/隐藏 Docusaurus 项目中所有详细标签状态的按钮?
- tensorflow - 为什么我使用 keras 和 tf.keras 得到不同的训练结果?
- c# - 如何检测 .NET Core 中的运行时代码生成?
- ruby - 有没有办法强制 RDoc 不设置与类或模块相对应的单词样式?
- python - 向空闲/终端显示表情符号字符的方法?UnicodeEncodeError - Tk 中不支持非 BMP 字符
- php - 如果作者是特定的人,请在 WordPress 中执行某些操作
- python - 如何根据不同列中的唯一变量获取 csv 文件中列的运行总计?
- php - ReCaptcha 在调用 siteverify 时随机返回空值
- c++ - 面向 Windows Server Core 的 C++