我有一個包含五列和五行的數據框。數據幀是這樣的:具有多個y軸的分組箱
df <- data.frame(
day=c("m","t","w","t","f"),
V1=c(5,10,20,15,20),
V2=c(0.1,0.2,0.6,0.5,0.8),
V3=c(120,100,110,120,100),
V4=c(1,10,6,8,8)
)
我想要做一些情節,所以我用了ggplot
,特別是geom_bar
:
ggplot(df, aes(x = day, y = V1, group = 1)) + ylim(0,20)+ geom_bar(stat = "identity")
ggplot(df, aes(x = day, y = V2, group = 1)) + ylim(0,1)+ geom_bar(stat = "identity")
ggplot(df, aes(x = day, y = V3, group = 1)) + ylim(50,200)+ geom_bar(stat = "identity")
ggplot(df, aes(x = day, y = V4, group = 1)) + ylim(0,15)+ geom_bar(stat = "identity")
我的問題是,怎樣才能做一個分組ggplot
與geom_bar
與多個y軸?我想在X軸的一天,每天我想繪製四個垃圾桶V1,V2,V3,V4
,但具有不同的範圍和顏色。那可能嗎?
編輯
我想y軸看起來像這樣:
在'ggplot2'文檔例如如何爲繪製準備數據請看下圖: http://stackoverflow.com/documentation/r/1334/ggplot2#t=201607261933589547859。 – Alex
'ggplot2'不支持多個y軸。如果你想這樣的事情會非常複雜(http://stackoverflow.com/questions/3099219/plot-with-2-y-axes-one-y-axis-on-the-left-and-another- y軸 - 上的右)。 – Alex
閱讀上面鏈接問題的最後一個答案。這個答案來自ggplot2軟件包的作者。 – Alex