我在計算子集數據時遇到了一個問題。不過,最初我從文件提取一些信息到另一個。然後,我嘗試計算每個器官的患者人數。正確運行之前的命令現在給我一個錯誤。它不顯示任何錯誤 - 只是錯誤地計算值。R中子集化後的Miscalculation
輸入文件是在這個環節:https://www.dropbox.com/sh/8bo4b4dpmydj19w/AADZ7WuoecrjPwm_qyF8NRMza?dl=0
這是我的命令行。
Clinical_Samples_map = read.xls("b.xlsx") # calling my file
Clinical_Samples_Original = read.xls("a.xlsx", sheet=1) # the file where I get additional information
Clinical_Samples_map$AnatomicLocation = Clinical_Samples_Original[match(Clinical_Samples_map$SampleID, Clinical_Samples_Original$TubeName),"AnatomicLocation"]
map<-Clinical_Samples_map # Just changing the name
# Anatomic Location
sub_map_AnatomicLocation <- map[!duplicated(map$patient_number), ] # Excluding the duplicate of patient by checking patient_number column
sub_map_AnatomicLocation <- data.frame(sub_map_AnatomicLocation)
sub_map_AnatomicLocation_patient <- subset(sub_map_AnatomicLocation, Disease != "Unknown" & AnatomicLocation != "Unknown") # Getting rid of "Unknown" value if there is any
AnatomicLocation_patient <- count_(sub_map_AnatomicLocation , c("Disease","AnatomicLocation"))
write.table(AnatomicLocation_patient, "AnatomicLocation_patient.txt",col.names = TRUE)
write.table(Clinical_Samples_map, "Clinical_Samples_map2.txt",col.names = TRUE)
但是,當我比較兩個寫入的txt文件我有不同的數字。有誰知道爲什麼發生這種情況?舉例來說,如果你看看CD迴腸的IT顯示3例但是當我看Clinical_Samples_map2.txt我可以算4
附加的東西,如果我嘗試生成一些情節與ggplot:
ggplot(data=Clinical_Samples_map, aes(x=Disease, y=AgeAtSampling, fill=Disease)) +
geom_boxplot(notch = TRUE) +
ggtitle("Clinical_Samples_map_Disease") +
scale_y_continuous(name = "Age at Sampling", breaks = seq(0, 80, 20), limits=c(0, 80)) +
scale_x_discrete(name = "Disease") +
geom_jitter(colour = "black", size = 2, width = 0.15, height = 0.3) +
theme(legend.position = "bottom") +
labs(fill = "Disease") +
theme(axis.title=element_text(face="plain", size="30", color="black",family = "Gill Sans MT"),
axis.text.x = element_text(colour="grey20",size=20,angle=45,hjust=.5,vjust=.5,face="plain"),
axis.text.y = element_text(colour="grey20",size=20,angle=0,hjust=1,vjust=0,face="plain"),
legend.text=element_text(face="plain", size="30", color="black"),
legend.title=element_text(face="plain", size="30", color="black"))
我得到了一個錯誤:
Error: Discrete value supplied to continuous scale
我認爲這就是問題所在。我可以克服這個來產生情節,但我不明白爲什麼它計算錯誤?
任何人都可以幫助解決這個問題嗎?我掙扎了很長時間,還沒搞清楚。
非常感謝。
Bahti
對不起我的錯誤...下面是使用過的圖書館:圖書館(gdata)和圖書館(dplyr)... – Lothlorian
請更新您的文章'庫'行,而不是在評論中,所有人都可以看到。 – Parfait