我有一堆隨着時間的測量,我想在R中繪製它們。下面是我的數據樣本。我有6次測量的每4個時間點:R ggplot2:使用stat_summary(mean)和對數刻度
values <- c (1012.0, 1644.9, 837.0, 1200.9, 1652.0, 981.5,
2236.9, 1697.5, 2087.7, 1500.8,
2789.3, 1502.9, 2051.3, 3070.7, 3105.4,
2692.5, 1488.5, 1978.1, 1925.4, 1524.3,
2772.0, 1355.3, 2632.4, 2600.1)
time <- factor (rep (c(0, 12, 24, 72), c(6, 6, 6, 6)))
這些數據的規模是任意的,其實我要正常化它,以便T的平均= 0是1
norm <- values/mean (values[time == 0])
到目前爲止好。使用ggplot
,我繪製了單個的點,以及通過平均在每一個時間點進了行:
require (ggplot2)
p <- ggplot(data = data.frame(time, norm), mapping = aes (x = time, y = norm)) +
stat_summary (fun.y = mean, geom="line", mapping = aes (group = 1)) +
geom_point()
不過,現在我想申請一個對數標度,這是我的麻煩就來了。當我這樣做:
q <- ggplot(data = data.frame(time, norm), mapping = aes (x = time, y = norm)) +
stat_summary (fun.y = mean, geom="line", mapping = aes (group = 1)) +
geom_point() +
scale_y_log2()
行不通過0走在t = 0,你所期望的,因爲日誌(1)== 0,取而代之的是線橫穿略低於0 y軸顯然, ggplot
在對數轉換後應用均值,這給出了不同的結果。我希望它在日誌轉換之前採取平均值。
我該如何告訴ggplot
先應用平均值?有沒有更好的方法來創建這個圖表?
這並不簡單。非常感謝! – amarillion 2010-08-02 13:41:12
注意:'scale_y_log2'不再存在,請使用'scale_y_continuous'而不是 – 2013-09-16 13:38:19