我试图ggplot2在y轴显示标签的位置制作切面图,x轴应显示两个不同尺度(在不同尺度上)的每个标签的值的折线图.到目前为止我有这个:
Data <- structure(list(label = structure(
c(1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L, 6L, 6L), .Label = c("A", "B", "C", "D", "E", "F"), class = "factor"),
facet = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L), .Label = c("A", "B"), class = "factor"), value = c(0.0108889081049711,
0.37984336540103, 0.0232500876998529, 0.777756493305787,
0.0552913920022547, 0.920194681268185, 0.0370863009011373,
0.114463779143989, 0.00536034172400832, 0.469208759721369,
0.0412159096915275, 0.587875489378348), group = c(1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1)), .Names = c("label", "facet",
"value", "group"), row.names = c(NA, -12L), class = "data.frame")
ggplot(Data, aes(x = label, y = value, group = group)) + geom_line() +
facet_grid(~ facet, scales = "free") + coord_flip()
Run Code Online (Sandbox Code Playgroud)
这创建了以下图:

问题是这些测量是在不同的尺度上,我更喜欢A情节的x限制从0到0.1,并且B图表的x限制从0到1.我认为scales = "free"应该解决这个问题,但它不会改变情节.
Bro*_*ieG 14
我想出了类似的东西df239:
ggplot(Data, aes(y = label, x = value, group=group)) + geom_path() +
facet_wrap( ~ facet, scales = "free")
Run Code Online (Sandbox Code Playgroud)
注意你必须使用geom_path,并注意点的顺序,因为只是切换x和y不一样coord_flip(不支持其他答案中所述facet_wrap).

| 归档时间: |
|
| 查看次数: |
8488 次 |
| 最近记录: |