這是我的數據結構:R,ggplot - 定製我的barplot
Accession Source Name NucSource Order color Counts Normalized
1 Str1 Our Str1 ch 1 #1C9099 66827 2.318683e-01
2 Str1_plasmid Our Str1 pl 2 #1C9099 26 9.021169e-05
3 Str2 Our Str2 ch 3 #1C9099 288211 1.000000e+00
4 Str2_plasmid Our Str2 pl 4 #1C9099 71858 2.493243e-01
5 Str3 Our Str3 ch 5 #1C9099 40600 1.408690e-01
6 Str3_plasmid Our Str3 pl 6 #1C9099 25266 8.766494e-02
7 Str4 NCBI Str4 ch 7 #A6BDDB 21339 7.403951e-02
8 Str5 NCBI Str5 ch 8 #A6BDDB 37776 1.310706e-01
9 Str6 NCBI Str6 ch 9 #A6BDDB 3596 1.247697e-02
10 Str7 NCBI Str7 ch 10 #A6BDDB 5384 1.868076e-02
11 Str7_plasmid NCBI Str7 pl 11 #A6BDDB 40903 1.419203e-01
12 Str8 NCBI Str8 ch 12 #A6BDDB 8948 3.104670e-02
13 Str9 NCBI Str9 ch 13 #A6BDDB 16557 5.744750e-02
14 Str9_plasmid NCBI Str9 pl 14 #A6BDDB 3738 1.296966e-02
15 Str10 NCBI Str10 ch 15 #A6BDDB 10067 3.492927e-02
16 Str11 NCBI Str11 ch 16 #A6BDDB 7306 2.534948e-02
17 Str12 NCBI Str12 ch 17 #A6BDDB 10313 3.578281e-02
我在其上運行下面的代碼:
p<-ggplot(data=myData, aes(x=Name, y=Normalized, fill=Source)) +
theme_few() +
xlab("Strain") + ylab("Normalized counts") +
geom_bar(stat="identity", aes(fill=myData$Source), colour="black", position="dodge") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.4)) +
geom_text(aes(label=myData$NucSource), vjust=-0.5) +
theme(legend.position="right") +
scale_fill_manual(values=as.character(color.convert$color)[2:3])
print(p)
什麼我想現在,對於像「Str1」這樣的例子,我有「chr」和「pl」這兩個條應該水平相鄰(也適用於「Str2」,「Str3」,「Str7」 「STR8」)。但對於像「Str4」那樣只有「ch」的情況,應該只有一個條。 所以酒吧不應該在彼此頂部,但水平排列。
編輯 - dput(頭(MYDATA的,20)):
結構(列表(保藏=結構(C(16L,17L,12L,13L,14L,15L, 1L, (「CP000517」, 「CP002081」,「CP002427」,「CP002429」,「CP002430_plasmid」,「CP003799」)。標籤= , 「CP009907」, 「CP009908_plasmid」, 「CP011386」, 「CP」, 「CP016827」, 「FAM22155」, 「FAM22155_plasmid」, 「FAM8105」, 「FAM8105_plasmid」, 「FAM8627」, 「FAM8627_plasmid」),類=「factor」),Source = structure(c(2L,2L, 2L,2L,2L,2L,1L,1L,1L,1L,1L,1L,1L,1L, 1L,1L,1L),標籤= c(「NCBI」,「我們的」 「),名稱= 結構(c(1L,1L,2L,2L,3L,3L,4L,5L,6L,7L,7L,8L,9L,9L, 10L,11L,12L),。標籤= c (FAM8627,FAM22155,FAM8105,DPC 4571,CNRZ32,H9,H10,R0052,KLDS1.8701,MB2-1, CAUH18 (1L,2L,1L,2L,1L,2L,1L,1L,1L,1L,2L,1L,1L,2L,1L) (1L,1L),標籤= c(「ch」,「pl」),class =「factor」),Order = 1:17,color = 結構,1L,2L,2L,2L,2L,2L,2L,2L,2L, 2L,2L,2L),標籤= c(「#1C9099」,「#A6BDDB」,「#ECE2F0」 「因素」), 計數= C(66827L,26L,288211L,71858L,40600L,25266L, 21339L,37776L,3596L,5384L,40903L,8948L,16557L,3738L, 10067L,7306L,10313L),歸一化的= C(0.231868318697066, 9.02116851889761 E-05,如圖1所示,0.249324279781133,0.140869016102786, 0.0876649399224873,0.0740395057787524,0.131070639219183, 0.0124769699976753,0.0186807581945172,0.141920329203257, 0.0310466984258061,0.0574474950643799,0.0129696645860151, 0.0349292705691316,0.0253494835381023,0.0357828118982273 )),.Names = C( 「登錄」, 「Source」,「Name」,「NucSource」,「Order」,「color」,「Counts」,「Normalized」),row.names = c(NA,17L), class =「data.frame」)
請問'dput(head(myData,20))'並將其複製/粘貼到您的問題中?這使我們更容易幫助您,而不必像您提供的那樣創建數據框。 –