r - 防止在 facet_wrap() 中重新排序
问题描述
我的 ggplot() 重新排序数据时遇到问题。我在下面有一个示例代码。我有数据,并重新排序了内容中的因子,但是在 facet_wrap() 中的 str_extract() 之后,数据在我重新排序之前被重新排序。有没有办法防止这种情况发生?对于我的实际代码,在 ggplot 的 facet_wrap() 中使用正则表达式对我来说很重要,
data <- chickwts
data <- mutate(data, time = 1:nrow(data))
lvl <- c("linseed", "meatmeal", "sunflower", "soybean",
"casein", "horsebean")
data$feed <- factor(data$feed, levels = lvl)
ggplot(data, aes(x = time, y = weight, color = feed)) +
geom_line(size = 1) + geom_point(size = 1.75) +
facet_wrap(~str_extract(feed,"[a-z]+"))
解决方案
推荐阅读
- java - 如何删除索引列表中的重复元素?
- testing - 是否可以从 TFS 测试管理 WebUI 触发 TFS 自动化测试?
- c# - C#交替数字,实现相同结果的更有效方法?
- c# - WPF ShowDialog 单击所有者窗口事件
- android - Android - 在 for 循环中创建多个 onClickListeners (Kotlin)
- c# - 我们可以将运行在 PC 上的 ActiveMQ 服务器与运行在 android 上的 ActiveMQ 客户端连接起来吗?
- typescript - 从高地流中的 aync 函数返回时如何处理元组?
- cors - Nuxt.JS 处理 CORS 请求
- vb.net - RadCombobox 不显示正确的属性值
- r - ggplot2中的数学表达式注释问题