在ggplot2中设置颜色轴限制

时间:2017-04-14 19:01:34

标签: r matlab ggplot2 colors heatmap

我正在尝试制作叶绿素荧光与深度和时间的热图。我的工作做得很好,但是我试图提高我的色彩对比度。我使用以下代码生成热图。

ggplot(subset(ctdamotInt2, variable == 'fluorescence'), aes(time, depth)) +
geom_tile(aes(fill = log10(value))) + scale_y_reverse(limits = c(110, 0)) +
scale_x_time(limits = c(min(subset(ctdamot, variable == 'nh4')$time) - 2 * 60^2, max(subset(ctdamot, variable == 'nh4')$time) + 2* 60^2)) +
geom_point(data = samplesCTD, aes( x = time, y = depth)) +
scale_fill_gradient2(low = "blue", mid = "white", high = "green")

Heatmap of chlorophyll vs depth and time

一般来说,我发现深绿色基本上没有得到利用,所以我的热图最终看起来已经褪色,并且在叶绿素荧光很有意义的情况下做不好的沟通如果我在matlab工作,我通过设置

来解决这个问题
 caxis([-1 0.4])

将所有值设置为高于0.4的最大绿色值。你不可能分辨出真正高值的相对差异,但你至少能够更好地了解构成大部分情节的中间值的相对差异。关于我如何能够获得更大比例的这个情节的任何建议都是绿色的?我想我可以手动重新调整输入值,但如果有更好的方法则不愿意。

编辑:应Mike H的要求

dput(head(ctdamotInt2,100))

    structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  1L, 1L, 1L, 1L, 1L, 1L, 1L,
    1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("temperature",  "salinity",
    "fluorescence", "oxygen", "nh4"), class = "factor"), 
        depth = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), time = structure(c(1482764087, 
    1482767687, 1482771287, 1482774887, 1482778487, 1482782087, 
    1482785687, 1482789287, 1482792887, 1482796487, 1482800087, 
    1482803687, 1482807287, 1482810887, 1482814487, 1482818087, 
    1482821687, 1482825287, 1482828887, 1482832487, 1482836087, 
    1482839687, 1482843287, 1482846887, 1482850487, 1482854087, 
    1482857687, 1482861287, 1482864887, 1482868487, 1482872087, 
    1482875687, 1482879287, 1482882887, 1482886487, 1482890087, 
    1482893687, 1482897287, 1482900887, 1482904487, 1482908087, 
    1482911687, 1482915287, 1482918887, 1482922487, 1482926087, 
    1482929687, 1482933287, 1482936887, 1482940487, 1482944087, 
    1482947687, 1482951287, 1482954887, 1482958487, 1482962087, 
    1482965687, 1482969287, 1482972887, 1482976487, 1482980087, 
    1482983687, 1482987287, 1482990887, 1482994487, 1482998087, 
    1483001687, 1483005287, 1483008887, 1483012487, 1483016087, 
    1483019687, 1483023287, 1483026887, 1483030487, 1483034087, 
    1483037687, 1483041287, 1483044887, 1483048487, 1483052087, 
    1483055687, 1483059287, 1483062887, 1483066487, 1483070087, 
    1483073687, 1483077287, 1483080887, 1483084487, 1483088087, 
    1483091687, 1483095287, 1483098887, 1483102487, 1483106087, 
    1483109687, 1483113287, 1483116887, 1483120487), class = c("POSIXct", 
    "POSIXt")), value = c(27.3483, 27.3483, 27.3483, 27.3483, 
    27.4404348314607, 27.5325696629213, 27.624704494382, 27.7168393258427, 
    27.8089741573034, 27.901108988764, 27.9932438202247, 28.0853786516854, 
    28.1006709677419, 28.1151870967742, 28.1297032258065, 28.1602961677656, 
    28.3392342471866, 28.5181723266075, 28.6971104060285, 28.8760484854494, 
    29.0549865648704, 29.1744078768732, 29.2330425521923, 29.2916772275114, 
    29.3503119028306, 29.4089465781497, 29.4675812534688, 29.5262159287879, 
    29.5233725024786, 29.5198033650201, 29.5162342275617, 29.5126650901032, 
    29.5090959526448, 29.5055268151863, 29.5019576777279, 29.4983885402694, 
    29.494819402811, 29.4392079391567, 29.3230472306014, 29.2068865220461, 
    29.0907258134908, 28.9745651049355, 28.8584043963802, 28.7422436878249, 
    28.6260829792696, 28.5099222707143, 28.5396702257581, 28.6045126836247, 
    28.6693551414913, 28.734197599358, 28.7990400572246, 28.8638825150912, 
    28.9287249729579, 28.9935674308245, 29.0584098886912, 29.1232523465578, 
    29.1880948044244, 29.2529372622911, 29.3177797201577, 29.3826221780244, 
    29.447464635891, 29.5123070937576, 29.4047436790674, 29.2746548739928, 
    29.1445660689182, 29.0144772638436, 28.8843884587691, 28.7542996536945, 
    28.6242108486199, 28.4941220435453, 28.4440444629526, 28.4161338799902, 
    28.3882232970279, 28.3603127140655, 28.3324021311032, 28.3044915481409, 
    28.2765809651785, 28.2486703822162, 28.2207597992539, 28.1928492162915, 
    28.1649386333292, 28.1370280503668, 28.1091174674045, 28.0812068844422, 
    28.0532963014798, 28.0253857185175, 27.9974751355552, 27.9695645525928, 
    27.9416539696305, 27.9137433866682, 27.8858328037058, 27.8579222207435, 
    27.8300116377811, 27.8021010548188, 27.7741904718565, 27.7462798888941, 
    27.7183693059318, 27.6904587229695, 27.6625481400071, 27.6346375570448
    )), .Names = c("variable", "depth", "time", "value"), row.names = c(NA,  100L), class = "data.frame")

0 个答案:

没有答案