创建一个水平小工具填充'对于带有R

时间:2016-03-17 02:34:30

标签: r plot ggplot2 gradient

我正在使用R并拥有一个包含两列的简单data.frame。一列为coverage,另一列为uniqueness。我需要生成一个如下图所示的图,其中x轴为1:length(df),y轴为coverage。我可以使用这个简单的代码构建没问题,但是我需要添加一个功能,其中uniqueness显示为沿x轴的渐变。我尝试了一些事情,我认为使用fillscale_colour_gradient()应该是答案,但它不适合我。

# barplot
library(ggplot2)
library(graphics)
barplot(df)

# more about barplot() function 
?barplot()

enter image description here

编辑:当前情节

enter image description here

  

dput(newData)   结构(list = coverage = c(3.36729582998647,3.36729582998647,   3.36729582998647,3.36729582998647,3.36729582998647,3.36729582998647,   3.36729582998647,3.93322563272433,3.95124371858143,3.95454371858143,   3.93182563272433,3.93182563272433,3.93182563272433,3.91202300542815,   3.91202300542815,3.91202300542815,3.91202300542815,3.93322563272433,   3.36729582998647,3.36729582998647,3.36729582998647,4.27666611901606,   4.27666611901606,4.29045944114839,4.29045944114839,4.29045944114839,   4.29045944114839,4.29045944114839,4.29045944114839,3.97029191355212,   4.20469261939097,4.20469261939097,5.17048399503815,5.17048399503815,   5.16478597392351,5.12396397940326,5.24702407216049,5.31811999384422,   5.03695260241363,5.03695260241363,3.55534806148941,3.55534806148941,   3.55534806148941,3.55534806148941,3.55534806148941,3.55534806148941,   3.55534806148941,3.55534806148941,3.55534806148941,3.55534806148941,   3.55534806148941,3.55534806148941,3.55534806148941,3.58351893845611,   3.58351893845611,3.58351893845611,3.58351893845611,3.58351893845611,   4.66343909411207,4.66343909411207,4.672288883446191,4.672288883446191,   4.67282883446191,4.67282883446191,4.68213122712422,4.68213122712422,   4.68213122712422,4.54329478227,4.52178857704904,4.52178857704904,   4.52178857704904,4.52178857704904,4.52178857704904,4.52178857704904,   4.52178857704904,3.71357206670431,4.18965474202643,4.47733681447821,   4.47733681447821,4.51085950651685,4.51085950651685,4.52178857704904,   4.53259949315326,4.53259949315326,4.55387689160054,4.56434819146784,   5.23110861685459,5.2257466737132,5.2257466737132,5.22035582507832,   5.2040066870768,5.20948615284142,5.2040066870768,5.2040066870768,   5.29330482472449,5.28826703069454,5.28826703069454,5.31811999384422,   5.31811999384422,5.31320597904179,5.30826769740121,5.31320597904179,   5.39816270151775,5.39816270151775,5.39816270151775,5.5834963087817,   6.10479323241498,6.10702288774225,6.10924758276437,6.10702288774225,   6.10924758276437,6.11809719804135,6.1527326947041,6.1527326947041,   6.19031540585315,6.14418563412565,6.18620862390049,6.18208490671663,   6.18208490671663,6.16961073249146,6.20455776256869,6.22257626807137,   6.22455842927536,6.23244801655052,6.2363695902037,6.27476202124194,   6.27476202124194,6.27664348934164,6.22653666928747,6.23048144757848,   6.23048144757848,6.25958146406492,6.26339826259162,6.33505425149806,   6.33682573114644,6.33859407820318,6.34388043412633,6.34738920965601,   6.3456363608286,6.36302810354046,6.361302477573,6.36302810354046,   6.36818718635049,6.36990098282823,6.35088571671474,6.35437004079735,   6.35610766069589,6.35610766069589,6.36647044773144,6.31716468674728,   6.32076829425058,6.32256523992728,6.32256523992728,6.31896811374643,   6.23441072571837,6.23441072571837,6.25190388316589,6.21060007702465,   6.20657592672493,6.27476202124194,6.27287700654617,6.27287700654617,   6.2709884318583,6.26909628370626,6.26339826259162,6.26339826259162,   6.25766758788264,6.22257626807137,6.19440539110467,6.28226674689601,   6.28226674689601,6.28226674689601,6.29156913955832,6.29526600143965,   11.0455902722788,11.0605574107758,11.0683712350503,11.071750274228,   11.0739397670939,11.0765732227783,11.0778873545197,11.0833110966291,   11.0838334262309,11.0849539777208,11.0965005166257,11.0927172087879,   11.0931737881036,11.0867626290829,11.0878034189527,11.0857974002258,   11.0760935211126,11.0667477313608,10.9871723112865,10.3838436594859,   10.3461842172496,10.2861956735217,10.066838635698,9.62350906446938,   9.59960834518178,9.58493381641726,9.55272367519805,9.55619700847904,   9.55937621211763,9.56212336983449,9.5262454033717,9.51332968849511,   9.5117774096603,9.46086560003161,9.45727857185611,9.45821555950958,   9.45813751072905,9.45602788772529,9.44065812703839,9.38915578944085,   9.33308883723524,4.30406509320417,4.30406509320417,4.29045944114839,   4.27666611901606,4.27666611901606,4.27666611901606,4.27666611901606,   4.27666611901606,4.27666611901606,4.30406509320417,4.31748811353631,   4.30406509320417,4.31748811353631,4.31748811353631,4.29045944114839,   4.29045944114839,4.29045944114839,4.29045944114839,4.29045944114839,   4.30406509320417,3.91202300542815,3.87120101090789,3.85014760171006,   3.29583686600433,3.29583686600433,3.29583686600433,2.94443897916644,   2.94443897916644,2.94443897916644,2.94443897916644,2.94443897916644,   3.80666248977032,3.80666248977032,4.40671924726425,5.91079664404053,   5.90808293816893,5.84643877505772,5.31320597904179,5.16478597392351,   5.17048399503815,5.17048399503815,3.25809653802148,3.25809653802148,   3.25809653802148,3.25809653802148,3.25809653802148,3.25809653802148,   3.25809653802148,3.25809653802148,3.25809653802148,3.29583686600433,   3.29583686600433,3.29583686600433,3.29583686600433,3.29583686600433,   3.29583686600433,3.29583686600433,3.29583686600433,3.29583686600433,   3.29583686600433,3.29583686600433,3.29583686600433,3.29583686600433,   3.29583686600433,3.29583686600433,3.29583686600433,3.29583686600433,   3.29583686600433,3.29583686600433,3.29583686600433,3.29583686600433,   3.29583686600433,5.14166355650266,4.9416424226093,4.79579054559674,   4.78749174278205,4.78749174278205,4.78749174278205,4.66343909411207,   2.07944154167984,2.07944154167984,3.61091791264422,3.61091791264422,   3.61091791264422,3.61091791264422,3.63758615972639,3.63758615972639,   3.63758615972639,3.63758615972639,3.63758615972639,3.66356164612965,   3.66356164612965,3.66356164612965,3.66356164612965,3.66356164612965,   3.66356164612965,3.66356164612965,3.66356164612965,3.66356164612965,   3.66356164612965,3.66356164612965,3.66356164612965,3.68887945411394,   3.68887945411394,3.68887945411394,3.68887945411394,3.68887945411394,   3.68887945411394,3.68887945411394,3.68887945411394,3.71357206670431,   3.71357206670431,3.71357206670431,3.71357206670431,3.71357206670431,   3.71357206670431,3.71357206670431,3.71357206670431,3.71357206670431,   3.71357206670431,3.71357206670431,3.71357206670431,3.71357206670431,   3.71357206670431,5.00394630594546,5.00394630594546,5.01063529409626,   4.95582705760126,4.70048036579242,4.85203026391962,4.85203026391962,   4.85203026391962,4.85203026391962,4.85203026391962,4.85203026391962,   4.85203026391962,4.84418708645859,4.83628190695148,4.83628190695148,   4.83628190695148,4.83628190695148,5.30330490805908,5.84354441703136,   5.8348107370626,5.83188247728352,5.82894561761021,5.82304589548302,   5.82304589548302,5.82600010738045,5.76205138278018,5.76205138278018,   5.82008293035236,5.8348107370626,5.83773044716594,5.84354441703136,   5.84354441703136,5.84643877505772,5.85793315448346,5.85507192220243,   5.85507192220243,5.97126183979046,5.98393628068719,6.04500531403601,   6.03787091992214,6.04025471127741,6.08677472691231,5.46383180502561,   5.54517744447956,5.54907608489522,5.54517744447956,5.55682806169954,   5.55682806169954,5.55682806169954,5.63121178182137,5.63478960316925,   5.64544689764324,5.64897423816121,5.64897423816121,5.655518181081985,   5.65948221575962,5.19295685089021,5.19295685089021,5.18738580584075,   5.18738580584075,5.26785815906333),uniqueness = c(1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,0,0576132,0.0669856,0.0696517,0.0696517,   0.0696517,0.07,7.07,0.0696517,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,0941176,0.941176,0.941176,0.181818,   0.186047,0.186047,0.186047,0.153846,0.152381,0.153846,0.153846,   0.152381,0.15534,0.153846,0.150943,0.150943,0.152381,0.152381,   0.152381,0.152381,0.8,0.8,0.8,0.8,0.8,0.8,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   0.894737,0.894737,0.894737,0.894737,0.894737,0.894737,0.894737,   0.894737,0.894737,0.894737,0.894737,0.894737,0.894737,0.894737,   0.894737,0.894737,0.894737,0.894737,0.894737,0.809524,0.85,   0.85,0.85,0.85,0.107595,0.107595,0.103896,0.104575,0.104575,   0.103896,0.102564,0.102564,0.101911,0.101266,0.101266,0.100629,   0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.111888,0.112676,0.112676,   0.113475,0.112676,0.0226629,0.022792,0.0249221,0.0248447,   0.0243902,0.0242792,0.0424403,0.0424403,0.0425532,0.0447368,   0.0447368,0.0445026,0.0448549,0.0445026,0.0445026,0.466667,   0.466667,0.705882,0.705882,0.705882,0.705882,0.705882,0.705882,   0.705882,0.705882,0.705882,0.705882,0.705882,0.705882,0.705882,   0.705882,0.705882,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,0.923077,0.923077,0.923077,0.0533808,0.0535714,0.0528169,   0.714286,0.714286,0.789474,0.789474,0.866667,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,   1,1,1,1,1,1,1,1,1,1,1,0,0.894737,0.100592,0.1,0.1,   0.0988372,0.0988372,0.0994152,0.0977011,0.0977011,0.0982659,   0.0977011,0.0977011,0.0971429,0.0965909,0.0923913,0.0923913,   0.0923913,0.0913978,0.0913978,0.0918919,0.0923913,0.0918919,   0.0939227,0.0939227,0.0939227,0.9375,0.941176,0.9411767,   0.941176,0.941176,0.941176,0.941176,0.941176,0.941176,0.941176   0.941176,0.941176,0.941176,0.941176,1,1,1,1,1)),. Name = c(" coverage",   "唯一性"),row.names = c(NA,-400L),class =" data.frame")

1 个答案:

答案 0 :(得分:1)

我不知道你是如何处理的,但这可能会对你有帮助,

ggplot(df, aes(1:nrow(df), uniqueness, fill = uniqueness)) + 
    geom_bar(stat = "identity")