- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 ggplot2 中创建一个多面点图,但无法获得内面
类别以我想要的顺序出现。绘制点图的代码是:
g <- ggplot(df2, aes(x=Y, y=label)) + geom_point()
g <- g + facet_grid(incentive ~ ., scale="free")
g <- g + geom_errorbarh(aes(xmax = Y + se, xmin = Y - se))
g <- g + geom_vline(xintercept=1/6, linetype=2, colour="red")
g <- g + opts(title="% Subjects Choosing Non-Focal Image",
strip.text.y = theme_text()
) + xlab("%") + ylab("Groups")
print(g)
> levels(df2$label)
[1] "0" "1" "1 cent" "5 cent" "6"
>
df2$label3 1 0 1 1 cent 5 cent 6
Levels: 0 < 1 < 1 cent < 5 cent < 6
>str(df2$label3)
Ord.factor w/ 5 levels "0"<"1"<"1 cent"<..: 1 2 3 4 5
df2 <- structure(list(Y = c(0.0869565217391304, 0.148148148148148, 0.172413793103448,
0.384615384615385, 0.5625), group = c(0L, 1L, 5L, 3L, 6L), se = c(0.0856368459098186,
0.079039229753282, 0.0762650540661762, 0.0805448741815074, 0.0726021684593052
), nudged = c(FALSE, TRUE, TRUE, TRUE, TRUE), incentive = structure(c(1L,
2L, 3L, 3L, 4L), .Label = c("Default behavior", "Imbalance only",
"Money only", "Money & Imbalance together"), class = "factor"),
label = structure(1:5, .Label = c("0", "1", "1 cent", "5 cent",
"6"), class = "factor"), plot_order = c(0, 1, 2, 3, 4)), .Names = c("Y",
"group", "se", "nudged", "incentive", "label", "plot_order"),
row.names = c("as.factor(group)0",
"as.factor(group)1", "as.factor(group)5", "as.factor(group)3",
"as.factor(group)6"), class = "data.frame")
最佳答案
您的问题是 facet_grid
正在以与激励值的顺序(0、1 美分、5 美分等)相冲突的顺序绘制激励类型(“默认行为”等),这就是为什么您没有得到您的排序想要在 Money Only 组中。修复它的最简单方法是重新订购您的 incentive
因素,以便将默认行为绘制在底部而不是顶部:
df2$incentive <- ordered( df2$incentive,
levels = rev(c("Default behavior", "Imbalance only",
"Money only", "Money & Imbalance together")))
关于r - 在 ggplot2 的分面点图中绘制顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4774804/
我是一名优秀的程序员,十分优秀!