2012-07-23 85 views
0

我試圖通過x軸的發展階段在y軸上生成重量圖。有數百個樣本在每個發育階段都包含數據點,我試圖從它們中提取增長率曲線。我不知道如何以x軸代表三個分類變量(「ColonyMass_At_Wrkr_Eclosion」,「ColonyMass_4wksLater」和「ColonyMass_2mnthsLater」),也不知道如何連接同一個人的數據點跨越變量(例如創建一個曲線族,如果有意義的話)。使用dput()重現我的數據框時遇到了一些困難,但我盡了最大的努力。有什麼建議麼?太謝謝你了!:如何在x軸上繪製分類變量的散點圖R

just_growth_data=structure(list(ColonyMass_At_Wrkr_Eclosion = c(NA, 117L, NA,  
53L, NA, 91L, 85L, 111L, 96L, NA, 112L, 90L, 112L, 120L, 110L, 
109L, NA, NA, 99L, 86L, 108L, 109L, 87L, 108L, 116L, 137L, 108L, 
NA, NA, NA, 93L, NA, 96L, 98L, 87L, NA, 111L, NA, 114L, NA, 11L, 
123L, 113L, 130L, 134L, NA, NA, 96L, NA, NA, 15L, 74L, NA, NA, 
75L, 96L, 88L, NA, 122L, NA, 101L, 83L, 123L, 89L, 85L, NA, 112L, 
98L, 87L, 123L, 115L, 16L, 125L, NA, 91L, NA, 85L, 76L, 122L, 
95L, 113L, 116L, 102L, 132L, 11L, 105L, 112L, 102L, 8L, NA, 113L, 
NA, 93L, 104L, 119L, 116L, 112L, 77L, NA, NA, 105L, 105L, 41L, 
99L, NA, 113L, 120L, 130L, 98L, 122L, 118L, NA, NA, 97L, NA, 
NA, NA, 104L, 103L, 110L, 25L, 118L, 98L, 123L, NA, 97L, NA, 
7L, 118L, NA, 82L, NA, 103L, 106L, 113L, NA, 115L, 123L, 124L, 
38L, 26L, 102L, 90L, NA, 59L, 102L, 82L, 120L, 113L, 116L, 117L, 
116L, 62L, 93L, 91L, 102L, 121L, 120L, NA, 111L, 97L, 63L, 109L, 
113L, 102L, 125L, 102L, 111L, 123L, 52L, 72L, NA, NA, 116L, NA, 
81L, 52L, 52L, NA, 105L, 123L, 87L, NA, 136L, 108L, NA, 120L, 
122L, NA, NA, 126L, NA, 47L, 111L, 118L, NA, NA, NA, NA, 109L, 
NA, 99L, 106L, 53L, 102L, 77L, 99L, NA, NA, NA, 114L, NA, 111L, 
NA, 113L, NA, 76L, 114L, NA, 120L, 113L, 97L, 134L, 98L, 118L, 
75L, 109L, 124L, 108L, NA, 124L, NA, 65L, 100L, NA, NA, 126L, 
11L, 97L, 76L, NA, NA, 106L, 110L, 3L, 116L, NA, NA, 135L, 96L, 
101L, NA, 92L, NA, NA, 118L, NA, 105L, 15L, 129L, 128L, 102L, 
NA, 92L, 100L, NA, NA, 71L, 103L, NA, 113L, NA, NA, 63L, NA, 
88L, 83L, 106L, 117L, 49L, NA, NA, 61L, 79L, NA, 91L, 102L, NA, 
93L, NA, NA, NA, 87L, 126L, 99L, NA, NA, 100L, 116L, 103L, 87L, 
37L, NA, 112L, NA, NA, 18L, NA, 94L, NA, NA, NA, 117L, 102L, 
62L, 96L, NA, 87L, 8L, NA, 86L, 61L, NA, 68L, 117L, 89L, NA, 
90L, NA, 104L, 94L, 102L, NA, 105L, 107L, 62L, 130L, 99L, 111L, 
NA, 106L, 98L, NA, 140L, 88L, 94L, NA, 122L, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), ColonyMass_4wksLater = c(NA, 
571L, NA, NA, NA, 736L, NA, NA, NA, NA, NA, 438L, NA, NA, 711L, 
NA, NA, NA, 537L, NA, 844L, NA, NA, NA, 560L, 561L, NA, NA, NA, 
NA, 594L, NA, NA, 457L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 714L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 417L, 
NA, NA, NA, 701L, NA, NA, NA, 25L, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 866L, NA, NA, 291L, NA, 659L, 354L, 743L, NA, NA, 696L, 
NA, NA, NA, NA, NA, NA, NA, 518L, NA, NA, NA, NA, NA, NA, 907L, 
27L, NA, NA, 625L, NA, NA, 957L, 804L, NA, NA, NA, 650L, NA, 
NA, NA, NA, NA, NA, NA, 699L, 632L, NA, NA, 518L, NA, NA, NA, 
NA, NA, NA, 527L, 541L, NA, NA, NA, NA, NA, 448L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 382L, NA, 431L, NA, 620L, 
NA, 296L, NA, 532L, NA, 485L, NA, NA, NA, NA, NA, NA, 153L, NA, 
NA, NA, NA, 23L, NA, NA, NA, 606L, NA, NA, NA, 550L, 766L, NA, 
426L, 786L, NA, NA, 289L, NA, 119L, 327L, NA, NA, NA, NA, NA, 
NA, NA, 602L, NA, 20L, NA, NA, NA, NA, NA, NA, 152L, NA, 592L, 
NA, NA, NA, 1235L, 197L, NA, 442L, NA, NA, 558L, NA, NA, NA, 
NA, 818L, NA, NA, NA, NA, NA, NA, NA, NA, 783L, NA, 519L, NA, 
NA, NA, 856L, 609L, NA, 397L, NA, NA, 1195L, NA, 473L, NA, NA, 
NA, NA, 370L, NA, NA, 3L, 561L, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 783L, NA, NA, NA, NA, NA, NA, 537L, NA, NA, NA, NA, NA, 
937L, NA, 696L, NA, NA, 859L, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 902L, 430L, NA, 11L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 354L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 682L, NA, 
NA, NA, NA, NA, 134L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 670L, 
NA, NA, NA, NA, NA, NA, 537L, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), ColonyMass_2mnthsLater = c(NA, 
445L, NA, NA, NA, 1817L, NA, NA, NA, NA, NA, 2683L, NA, NA, 1775L, 
NA, NA, NA, 429L, NA, 77L, NA, NA, NA, 279L, 23L, NA, NA, NA, 
NA, NA, NA, NA, 111L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 70L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 71L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 249L, NA, NA, NA, NA, 1249L, 636L, 710L, NA, NA, 27L, NA, 
50L, NA, NA, NA, NA, NA, 531L, NA, NA, NA, NA, NA, NA, 63L, NA, 
NA, NA, 416L, NA, NA, 400L, 902L, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, 116L, NA, NA, NA, 674L, NA, NA, NA, NA, NA, NA, 
1439L, 305L, NA, NA, NA, NA, NA, 93L, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 2L, NA, 1107L, NA, 13L, NA, 201L, 
NA, 470L, NA, 184L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, 72L, NA, NA, NA, 2727L, 33L, NA, 121L, 643L, 
NA, NA, 168L, NA, 160L, NA, NA, NA, NA, NA, NA, NA, NA, 1732L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 666L, 
60L, NA, 128L, NA, NA, 140L, NA, NA, NA, NA, 15L, NA, NA, NA, 
NA, 1726L, NA, NA, NA, NA, NA, 1966L, NA, NA, NA, 77L, 76L, NA, 
199L, NA, NA, 54L, NA, 377L, NA, NA, NA, NA, NA, NA, NA, NA, 
738L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1422L, NA, NA, 
NA, NA, NA, NA, 695L, NA, NA, NA, NA, NA, 15L, NA, 1058L, NA, 
NA, 680L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 534L, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 850L, NA, NA, NA, NA, NA, 11L, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 51L, NA, NA, NA, NA, NA, NA, 146L, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA)), .Names = c("ColonyMass_At_Wrkr_Eclosion", "ColonyMass_4wksLater", 
"ColonyMass_2mnthsLater"), class = "data.frame", row.names = c(NA, 
-622L)) 

just_growth_data_factor<-factor(c("ColonyMass_At_Wrkr_Eclosion", "ColonyMass_4wksLater", "ColonyMass_2mnthsLater")) 
x<-rep(just_growth_data_factor,622) 
qplot(just_growth_data_factor, x) 
+1

爲什麼所有的權重編碼爲'dput'的輸出因素是什麼? – mnel 2012-07-23 01:11:18

+0

我不確定。我使用read.csv讀取數據框,如果有幫助的話。 – Atticus29 2012-07-23 01:27:08

+0

權重應該是連續的(數字)?目前,每列中有300到500個缺失值是正確的?如果不是,請嘗試在'read.csv'調用中正確設置'na.string'。 – mnel 2012-07-23 01:36:47

回答

2
# add an id column (presumably rows are individuals) 
just_growth_data$id <- 1:nrow(just_growth_data) 

# melt the data, collapsing the three categorical columns down into two: 
# variable (the column name) and value (the column value) 
require(reshape) 
data.m <- melt(just_growth_data, id.vars="id") 

# a simple scatterplot with the original rows connected 
ggplot(data.m, aes(x=variable, y=value, group=id)) + 
    geom_line() + 
    geom_point() 

a plot from cleaned up data

+0

這正是我所期待的。謝謝! 有關如何用置信區間擬合邏輯曲線的任何建議?或者我應該將其作爲單獨的問題發佈? – Atticus29 2012-07-23 02:10:07

+0

有沒有什麼辦法可以在Base R中做到這一點,或者ggplot幾乎可以做到這一點? – Atticus29 2012-07-23 02:11:57

+1

@ Atticus29:針對邏輯曲線擬合發佈一個單獨的問題,因爲它不符合您的原始問題。大多數ggplot圖在基礎R中是可行的,但是ggplot被很多人喜歡,因爲語法非常容易理解,而且一旦你理解了它,就會表達更多。如果你沒有花太多時間學習基礎繪圖系統,我建議儘快切換到ggplot。 – Marius 2012-07-23 03:40:05

相關問題