2014-02-21 89 views
10

我試圖在ggplot2一個方位圖,其中Y軸顯示的標籤,x軸應該顯示線圖,在兩個不同的措施(這是在不同的尺度每個標籤的價值)。到目前爲止,我有這樣的:不同的軸限制在GGPLOT2

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() 

它創建了以下情節: enter image description here

的問題是,這些措施在不同的尺度,我寧願A情節有X限制從0到0.1和B情節有從0到1,我想應該scales = "free"解決這個X的限制,但它不會改變劇情。

+0

好問題,順便說一句。 – BrodieG

回答

8

我想出了類似的東西df239

ggplot(Data, aes(y = label, x = value, group=group)) + geom_path() + 
    facet_wrap(~ facet, scales = "free") 

請注意,您必須使用geom_path,並注意您的積分順序,因爲只是切換xy不等於coord_flip(它作爲在對方的回答指出沒有與facet_wrap支持)。

enter image description here

+0

工作正常!我必須通過標籤來確定。謝謝! –

3

手動更改軸的方向,問題是:* GGPLOT2目前不支持使用非笛卡爾座標或coord_flip無鱗*

ggplot(Data, aes(y = label, x = value, group = group)) + geom_line() + 
facet_grid(~ facet, scales = "free")