我試圖與直方圖一個簡單的小刻面2×1在GGPLOT2與GGPLOT2
data <- read.csv("/hist_distances.csv", check.names = FALSE, sep = ",")
mdata <- melt(data)
m <- ggplot(data, aes(x=Distance))
m + geom_histogram()
頭(數據)
給出:
Times Distance
1 3.093060 260.8840
2 2.557780 187.4960
3 0.263611 10.6584
4 2.880000 184.5970
5 5.035000 281.3490
6 6.952780 251.4730
頭(mdata)
給出:
variable value
1 Times 3.093060
2 Times 2.557780
3 Times 0.263611
4 Times 2.880000
5 Times 5.035000
6 Times 6.952780
和
尾(MDATA)
給出:
variable value
1739 Distance 1.103670
1740 Distance 1.695610
1741 Distance 3.795020
1742 Distance 6.651960
1743 Distance 0.719843
1744 Distance 6.504050
我曾嘗試:
m <- ggplot(mdata, aes(x=value)) +
geom_histogram() +
m + facet_wrap(~ variable)
沒有成功。
我怎樣才能生成一個多面的圖形,而不是頂部的變量「次」的直方圖和底部的變量「距離」的直方圖?
你見過[facet_wrap(http://docs.ggplot2.org/0.9.3.1/facet_wrap.html)?嘗試'facet_wrap(〜變量)'在你的情況。 – David
哎呀,是的,我更新了問題 – Rodolphe
'facet_wrap(〜variable)'不適合你,因爲它會產生1x2而不是2x1圖?使用'facet_grid(variable〜。)'而不是'facet_wrap'會產生一個2x1圖。 – David