geom_bar() + pictograms, how to?

后端 未结 2 1676
北海茫月
北海茫月 2020-12-28 19:27

(See bottom of post for updates)

Initial post, 2014-07-29 11:43:38Z

I saw this graphics on the Economist\'s website and wondered if it\'s possible to pro

2条回答
  •  春和景丽
    2020-12-28 20:01

    gridSVG offers support for svg features unavailable to the R engine, such as fill patterns and arbitrary clipping. This example can easily be adapted for ggplot2,

    enter image description here

    library(grid)
    library(gridSVG)
    require(ggplot2)
    
    p <- ggplot(df3, aes(what, units)) + 
      geom_bar(colour="black", stat="identity") +
      coord_flip()
    
    pattern <- pattern(circleGrob(r=.4, gp=gpar(fill="grey")),
                       width=.05, height=.05)
    registerPatternFill("circles", pattern)
    gridsvg("pattern.svg")
    print(p)
    grid.force()
    grid.patternFill("geom_rect.rect", grep=TRUE, group=FALSE,
                     label=rep("circles", length(levels(df3$what))))
    dev.off()
    

提交回复
热议问题