r - 如何更改 x 轴标签?
问题描述
这是我用来尝试获取附件中的输出的代码:
fun_plot5 <- function(ycol, ylab, xcol, data) {
xx3 <- paste(ycol, xcol, sep = "~")
xx3 <- as.formula(xx3)
plotmeans(xx3, data = get_proposer,
xlab = "Gender", ylab = ylab,
main = "Mean Plot with 95% CI")
}
y_cols6 <- names(get_proposer[24:29])
y_lab6 <- c("Actual Offer (by A)", "Actual Amount Transferred to Partner (Bot)", "Actual Payoff (for A)", "Practice Offer (by A)", "Pradtice Amount Transferred to Partner (Bot)", "Practice Payoff (for A)")
old_par4 <- par(mfrow = c(3,3))
mapply(fun_plot5, y_cols6, y_lab6,
MoreArgs = list(
xcol = "gender",
data = get_proposer
))
我正在尝试将 x 轴值(对于所有图)从 1 和 2 分别更改为“男性”和“女性”。我尝试在上面代码的末尾包含这行代码,但我仍然无法得到我想要的结果。
fun_plot5 +
scale_x_discrete(limits = c("Male", "Female"))
当我将此行添加到使用 ggplot 的其他绘图之一时,它起作用了。但它不适用于当前的情节,附后。我该怎么做呢?
非常感谢!
已更新数据
# A tibble: 31 x 10
similar_task age gender income actual_offer actual_payoff actual_partner_transfer practice_partner_transfer practice_offer practice_payoff
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 5 29 1 4 40 126 66 48 30 118
2 3 36 1 4 100 273 273 180 100 180
3 5 39 2 2 0 100 0 0 0 100
4 3 25 1 7 100 6 6 195 100 195
5 3 28 2 7 25 99 24 84 50 134
6 2 45 2 5 80 29 9 42 100 42
7 3 30 1 6 100 45 45 123 100 123
8 5 37 1 3 0 100 0 0 0 100
9 2 38 2 2 25 99 24 63 25 138
10 1 25 1 1 100 183 183 285 100 285
# ... with 21 more rows
我在绘图中使用的列(附件)可以在数据的最后几列中找到,从“actual_offer”到“practice_payoff”(或者,整个数据集中的第 24:29 列)。
解决方案
在 plotmeans 文档中,legends 参数被定义为包含用于标记组的字符串的向量。当您在 plotmeans 调用中尝试 legends=c("Male, "Female") 时会发生什么?
推荐阅读
- c++ - 当涉及部分虚拟继承时,这是计算创建的基类对象数量的正确方法吗?
- excel - 匹配来自多个单元格的部分数据并返回值
- python - ImportError:没有名为 pageObjects.LoginPage 的模块
- swiftui - SwiftUI 如何从 ObservableObject 类切换 Struct 中的 Bool 并显示警报以通知用户
- laravel - Laravel 登录页面未显示布局主题
- npm - ENOSYS:功能未实现
- python - 如何使 MkDocs 侧边菜单中的页面可扩展?
- python - 无法使用 python 捕获图像(图像损坏)
- c# - Windows 窗体 | MenuStrip 子项 (ToolStripMenuItem) 更改光标不起作用
- python - 打印每 10 个数字,总是单独打印第一个值