![](/img/trans.png)
[英]Setting different axis limits for each facet in ggplot2 not using scales = “free”
[英]Different axis limits per facet in ggplot2
我試圖在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()
這將創建以下圖:
問題在於度量的尺度不同,我希望A
圖的x范圍從0到0.1, B
圖的x范圍從0到1。我認為scales = "free"
應該可以解決此問題,但是不會改變情節。
我想出了類似df239
東西:
ggplot(Data, aes(y = label, x = value, group=group)) + geom_path() +
facet_wrap( ~ facet, scales = "free")
請注意,您必須使用geom_path
,並注意點的順序,因為僅切換x
和y
與coord_flip
( facet_wrap
不支持其他答案中facet_wrap
)。
手動更改軸方向,問題是:* ggplot2當前不支持具有非笛卡爾坐標或coord_flip的自由刻度。
ggplot(Data, aes(y = label, x = value, group = group)) + geom_line() +
facet_grid(~ facet, scales = "free")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.