3
我對R很陌生,我有以下問題。使用不同變量的數據在條形圖中繪製百分比
我有這樣一個data.frame:
mydata.df <- data.frame(ID.name = c("1000", "1000", "1000", "1001","1001",1001,"1002","1002"),
project_name = c("project1", "project1", "project1", "project1","project1","project1","project2", "project2"),
Canonical_Hugo_Symbol = c("gene1", "gene3", "gene1", "gene1","gene3","gene4","gene1", "gene2"))
,我試圖繪製x上的不同的基因,佔的事實,一些基因只是在一個project_set和其他Y上的百分比在另一個。
我曾嘗試用:
q <- qplot(Canonical_Hugo_Symbol, data= mydata.df, geom="bar", fill= project_name, y = (..count..)/sum(..count..))
q + theme(axis.text.x=element_text(angle=-90, hjust = 1)) + stat_bin(geom = "text", aes(label = paste(round((..count..)/sum(..count..)*100), "%")), vjust = 5)
,但作爲一個例子基因2只是存在於項目2和應具有的比例爲100%,因爲是存在於所有(之一)的病人。
非常感謝!
我只是想編輯的data.frame,使其更加「真實」
dput(subset_mydata[c(1:10,1065:1077),c(3,9,20)])
structure(list(ID.name = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 140L, 140L, 140L, 140L, 141L, 141L, 141L, 141L,
141L, 141L, 142L, 142L, 142L), .Label = c("", "1075", "1104",
"1108", "1120", "1121", "1137", "1258", "1264", "1280", "1286",
"1310", "1317", "1338", "1392", "1401", "1435", "1477", "1480",
"1494", "1519", "1574", "1588", "1595", "1607", "1611", "1644",
"1645", "1651", "1653", "1654", "1673", "1687", "1702", "1714",
"1740", "1776", "1781", "1812", "1835", "1838", "1857", "1874",
"1890", "1899", "1911", "1933", "1936", "1999", "2006", "2046",
"2063", "2079", "2081", "2088", "2116", "2135", "2144", "2147",
"2155", "2166", "2167", "2176", "2183", "2200", "2209", "2223",
"2253", "2256", "2442", "2444", "2453", "2456", "2462", "2467",
"2472", "2482", "2497", "2504", "2507", "2513", "2518", "2523",
"2567", "2568", "2576", "2578", "2598", "2600", "2619", "2623",
"2625", "2632", "2636", "2646", "2652", "2659", "2660", "2676",
"2680", "2682", "2705", "2711", "2756", "2765", "2772", "2793",
"2803", "2854", "2856", "2882", "2912", "2916", "2919", "3058",
"3063", "3114", "3116", "3117", "3125", "3132", "3140", "3145",
"3175", "3181", "3248", "3383", "3431", "3436", "3442", "3472",
"3576", "3639", "4093", "FL1_01215", "FL10_01501", "FL12_01593",
"FL13_01598", "FL16_01738", "FL17_01752", "FL18_01763", "FL19_01881",
"FL2_01222", "FL22_02025", "FL23_02032", "FL24_02085", "FL25_02175",
"FL26_02242", "FL28_02459", "FL3_", "FL30_02558", "FL35_02726",
"FL37_02808", "FL41_02865", "FL43_02926", "FL44_02994", "FL45_03018",
"FL47_03119", "FL48_03128", "FL55_03303", "FL62_03406", "FL64_03418",
"FL65_03421", "FL69_03484", "FL7_01306", "FL70_03517", "FL71_03534",
"FL76_03644", "FL77_03651", "FL8_01425"), class = "factor"),
project_name = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
), .Label = c("", "FL_Ontogeny", "Hemoseq1"), class = "factor"),
Canonical_Hugo_Symbol = structure(c(174L, 158L, 113L, 113L,
97L, 175L, 14L, 9L, 35L, 65L, 14L, 14L, 14L, 111L, 123L,
113L, 113L, 160L, 50L, 50L, 25L, 25L, 131L), .Label = c("",
"ABCA7", "ACTA2", "ACTB", "ALMS1", "ARID1A", "ARID1B", "ARID2",
"ARID3A", "ASXL1", "ATM", "B2M", "BCAS3", "BCL2", "BCL7A",
"BCL9", "BCORL1", "BCR", "BIRC3", "BLNK", "BRAF", "BRD2",
"BRWD3", "BTG1", "BTG2", "BTG3", "CA10", "CARD11", "CCDC80",
"CCND1", "CCND2", "CCND3", "CD40", "CD58", "CD79A", "CD79B",
"CDH23", "CDK4", "CDK6", "CDKN2A", "CDKN2B", "CELSR2", "CHD1",
"CHD2", "CHRM3", "CIITA", "CNOT1", "COL4A2", "COL6A2", "CREBBP",
"CRLF2", "CTSS", "CUL9", "CXCR4", "DDX3X", "DGKG", "DIRAS3",
"DLEU2", "DMD", "DNAH9", "DNM2", "DNMT3A", "DST", "DTX1",
"EP300", "EPHA6", "EPHA7", "EPRS", "ETS1", "ETV6", "EZH2",
"FAM135B", "FAM155A", "FAM18A", "FAS", "FAT2", "FBXO11",
"FCGR2A", "FCGR3A", "FOXO1", "GNA13", "GNAS", "GNB1", "GNB2",
"GOPC", "HCK", "HEATR1", "HUWE1", "ID3", "IDH1", "IDH2",
"IKBKE", "IKZF1", "IKZF2", "IKZF3", "IRF4", "IRF8", "JAK1",
"KAT2A", "KAT2B", "KAT5", "KDM6A", "KIF20B", "KLHL6", "LRRC16A",
"MALT1", "MAP3K14", "MAP4K1", "MCL1", "MDM2", "MEF2B", "MLL",
"MLL2", "MPDZ", "MSH6", "MTAP", "MUC16", "MUM1", "MYC", "MYD88",
"NBAS", "NF1", "NFKB2", "NOTCH1", "NOTCH2", "NPM1", "NR3C1",
"OSBP2", "P2RY8", "PASD1", "PAX5", "PCLO", "PDGFC", "PDGFRA",
"PDGFRB", "PHF6", "PIK3CA", "PIK3CD", "PIK3R1", "PIM1", "POSTN",
"PRKDC", "PTEN", "RASSF8", "RB1", "RELN", "RET", "RFTN1",
"RFX7", "RHOA", "RIPK3", "RNF213", "ROS1", "SAMD9", "SBF1",
"SETD2", "SF3B1", "SGK1", "SIN3A", "SLITRK6", "SMARCA2",
"SMARCA4", "SMARCB1", "SOCS1", "SOX5", "STAT3", "STAT6",
"SWAP70", "SYK", "TBL1XR1", "TET2", "TMEM30A", "TNFAIP3",
"TNFRSF14", "TP53", "TRAF2", "TRAF3", "TRAF6", "TTC27", "TYK2",
"U2AF1", "UBR5", "UGGT1", "ULK4", "UNC13B", "UNC5C", "UNC5D",
"USP6", "VPS13A", "XPO1", "ZMAT4", "ZNF608", "ZNF708", "ZRSR2"
), class = "factor")), .Names = c("ID.name", "project_name",
"Canonical_Hugo_Symbol"), row.names = c(1L, 49L, 94L, 96L, 111L,
115L, 125L, 127L, 134L, 138L, 18794L, 18796L, 18797L, 18798L,
18800L, 18801L, 18802L, 18803L, 18805L, 18806L, 18809L, 18810L,
18814L), class = "data.frame")
我完全被你的命名困惑。什麼是病人? – ziggystar
ID.name是患者 – user3300849
目前文本標籤分別是:12%,38%,12%,25%,12%。請說明您希望他們是什麼:從您的問題,它不是很清楚所需的輸出是什麼。 – tonytonov