我正在製作一個堆積面積圖表,但並不完全在那裏。我已經跟隨以前的帖子,並嘗試了許多相同代碼的迭代,結果相同或更差。這是最成功的:Ggplot2,我的數據在哪裏?
ggplot(trtmeans, aes(x = year, y = dist, fill = factor(point))) + geom_area(position = 'stack')+ facet_wrap(~ trt)
這裏是我的數據框的頭:
year trt point dist
2009 C2 2.5 0.07819708
2009 C2 10 0.24723689
2009 C2 22.5 0.17690575
2009 C2 45 0.28355538
2009 C2 80 0.21410490
2009 CC 2.5 0.09657976
和文本文件的鏈接:https://www.dropbox.com/s/2m1bj970jj8rj7f/stackedplot.txt
這裏是結果:
我沒有任何問題,使它成爲一個堆疊的barplot,但我想多年來持續展示它。我不認爲這會很難。
而且dput(head(trtmeans))
:
structure(list(year = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2008",
"2009", "2010", "2011", "2012", "2013", "(all)"), class = "factor"),
trt = structure(c(1L, 1L, 1L, 1L, 1L, 2L), .Label = c("C2",
"CC", "CCW", "P", "PF", "S2", "(all)"), class = "factor"),
depth = structure(c(1L, 2L, 3L, 4L, 5L, 1L), .Label = c("5",
"15", "30", "60", "100", "(all)"), class = "factor"), point = structure(c(5L,
4L, 3L, 2L, 1L, 5L), .Label = c("80", "45", "22.5", "10",
"2.5"), class = c("ordered", "factor")), mass = c(0.039049865125,
0.1215071878125, 0.084692273125, 0.147087857875, 0.110562685125,
0.0798292900625), coresum = c(0.5028998690625, 0.5028998690625,
0.5028998690625, 0.5028998690625, 0.5028998690625, 0.774738473875
), dist = c(0.0781970752917714, 0.247236893004015, 0.176905750464174,
0.283555383459544, 0.214104897780495, 0.0965797557709145)), .Names = c("year",
"trt", "depth", "point", "mass", "coresum", "dist"), row.names = c(68L,
70L, 72L, 74L, 76L, 79L), class = "data.frame")
請提供'dput(trtmeans)輸出'在它轉換爲數值型變量編輯你的問題。 – Thomas
@joran:情況並非如此:'geom_area'確實需要'y'。 –
@DavidRobinson Hrm。你是對的。該文件似乎在這一點上具有誤導性。 – joran