r - geom_bar: color gradient and cross hatches (using gridSVG), transparency issue -


using awesome ggplot package, want barplot fill aesthetic mapped continous variable, qvalues , on top of texture, stripes , cross hatches.

the colour gradient important because represents significance while texture show category, "a", "b", , overlap. diagonals in 1 way, opposite way , cross hatches respectively. know venn diagram job, 35 samples , comparison easier see think.

the fill trivial, however, texture 1 tricky. on so, @baptise (see here , here) managed output dummy data: crossbars

the issue transparency of crosses's background. if possible alpha working on background in grid.patternfill() function great. unfortunately, in hands doesn't work.

any appreciated.

dummy data can loaded here:

dfso <- structure(list(sample = c("s1", "s2", "s1", "s2", "s1", "s2"),    qvalue = c(14.704287341, 8.1682824035, 13.5471896224, 6.71158432425,    12.3900919038, 5.254886245), type = structure(c(1l, 1l, 2l,    2l, 3l, 3l), .label = c("a", "overlap", "b"), class = "factor"),    value = c(897l, 1082l, 503l, 219l, 388l, 165l)), class = c("tbl_df",    "tbl", "data.frame"), row.names = c(na, -6l), .names = c("sample",    "qvalue", "type", "value")) 

code here:

library("ggplot2") library("gridsvg") library("gridextra") library("dplyr") library("rcolorbrewer")  cols <- brewer.pal(7,"ylorrd") pso <- ggplot(dfso)+   geom_bar(aes(x = sample, y = value, fill = qvalue, linetype = type), width = .8, colour = "black", stat = "identity", position = "stack", alpha = 1)+   theme_classic(18)+   theme( panel.grid.major = element_line(colour = "grey80"),      panel.grid.major.x = element_blank(),      panel.grid.minor = element_blank(),      legend.key = element_blank(),      axis.text.x = element_text(angle = 90, vjust = 0.5))+   guides(linetype = false) +   ylab("count")+   scale_fill_gradientn("-log10(qvalue)", colours = cols, limits = c(0, 20))+   scale_linetype_manual(values = c("dotted", "solid", "dotted"))+   scale_y_continuous(expand = c(0, 0), limits = c(0, 2000))  # gridsvg pat1 <- pattern(linesgrob(gp = gpar(col="black", lwd = 1)),                 width = unit(5, "mm"), height = unit(5, "mm"),                 dev.width = 1, dev.height = 1) pat2 <- pattern(linesgrob(x = unit(0:1, "npc"), y = unit(1:0, "npc"),                           gp = gpar(col="black", lwd = 1)),                 width = unit(5, "mm"), height = unit(5, "mm"),                 dev.width = 1, dev.height = 1) crossgrob <- gtree(children = glist(linesgrob(gp = gpar(col="black", lwd = 1)), linesgrob(x = unit(0:1, "npc"), y = unit(1:0, "npc"), gp = gpar(col="black", lwd = 1)))) registerpatternfill("hash1", pat1) registerpatternfill("hash2", pat2) registerpatternfill("cross", grob = crossgrob, dev.width = 1, dev.height = 1, width = unit(5, "mm"), height = unit(5, "mm")) gridsvg("crossbars.svg", width = 10) print(pso) grid.force() grid.patternfill("geom_rect.rect", alpha = 0.2, grep = true, group = false,                  label = rep(c("hash1", "cross", "hash2"), 1)) dev.off() 

in grid.patternfill alpha parameter suppose give transparency, far understood it. but, has no effect, , colour lost. filled patterns first bar see contrast.

edit: alpha working fine, acts on pattern itself, i.e lines. explains why lines appear pale. issue more background assumed white , without transparency.

the linetype mapping attempt highlight overlap part, not nice. if transparency works gridsvg discard part , keep solid line way.

many in advance,

aurelien

if of use, output of sessioninfo():

r version 3.2.1 (2015-06-18) platform: x86_64-apple-darwin14.3.0 (64-bit) running under: os x 10.10.4 (yosemite) locale: [1] en_us.utf-8/en_us.utf-8/en_us.utf-8/c/en_us.utf-8/en_us.utf-8 attached base packages: [1] grid      stats     graphics  grdevices utils     datasets  methods   base      other attached packages: [1] gridextra_0.9.1    rcolorbrewer_1.1-2 dplyr_0.4.1        gridsvg_1.4-3      ggplot2_1.0.1      loaded via namespace (and not attached):  [1] rcpp_0.11.6      xml_3.98-1.3     assertthat_0.1   digest_0.6.8     mass_7.3-42      plyr_1.8.3       dbi_0.3.1         [8] gtable_0.1.2     magrittr_1.5     scales_0.2.5     stringi_0.5-5    reshape2_1.4.1   labeling_0.3     proto_0.3-10     [15] rjsonio_1.3-0    tools_3.2.1      stringr_1.0.0    munsell_0.4.2    parallel_3.2.1   colorspace_1.2-6 

this not answer, provide following code reference might see how might accomplish task. live version here. think easier entirely d3 or library built on `d3

library("ggplot2") library("gridsvg") library("gridextra") library("dplyr") library("rcolorbrewer")  dfso <- structure(list(sample = c("s1", "s2", "s1", "s2", "s1", "s2"),                         qvalue = c(14.704287341, 8.1682824035, 13.5471896224, 6.71158432425,                                    12.3900919038, 5.254886245), type = structure(c(1l, 1l, 2l,                                                                                    2l, 3l, 3l), .label = c("a", "overlap", "b"), class = "factor"),                         value = c(897l, 1082l, 503l, 219l, 388l, 165l)), class = c("tbl_df",                                                                                    "tbl", "data.frame"), row.names = c(na, -6l), .names = c("sample",                                                                                                                                             "qvalue", "type", "value"))  cols <- brewer.pal(7,"ylorrd") pso <- ggplot(dfso)+   geom_bar(aes(x = sample, y = value, fill = qvalue), width = .8, colour = "black", stat = "identity", position = "stack", alpha = 1)+   ylim(c(0,2000)) +    theme_classic(18)+   theme( panel.grid.major = element_line(colour = "grey80"),          panel.grid.major.x = element_blank(),          panel.grid.minor = element_blank(),          legend.key = element_blank(),          axis.text.x = element_text(angle = 90, vjust = 0.5))+   ylab("count")+   scale_fill_gradientn("-log10(qvalue)", colours = cols, limits = c(0, 20))  # use svglite , htmltools library(svglite) library(htmltools)  # svg tag pso_svg <- htmlsvg(print(pso),height=10,width = 14)  browsable(   attachdependencies(     taglist(       pso_svg,       tags$script(         sprintf( "   var data = %s    var svg = d3.select('svg');    svg.select('style').remove();    var bars = svg.selectall('rect:not(:last-of-type):not(:first-of-type)')      .data(d3.merge(d3.values(d3.nest().key(function(d){return d.sample}).map(data))))    bars.style('fill',function(d){     var t = textures               .lines()               .background(d3.rgb(d3.select(this).style('fill')).tostring());      if(d.type === 'a') t.orientation('2/8');     if(d.type === 'overlap') t.orientation('2/8','6/8');     if(d.type === 'b') t.orientation('6/8');      svg.call(t);     return t.url();   }); "               ,           jsonlite::tojson(dfso)         )       )     ),     list(       htmldependency(         name = "d3",         version = "3.5",         src = c(href = "http://d3js.org"),         script = "d3.v3.min.js"       ),       htmldependency(         name = "textures",         version = "1.0.3",         src = c(href = "https://rawgit.com/riccardoscalco/textures/master/"),         script = "textures.min.js"       )     )   ) ) 

Comments