0

I'd like to plot a (kind of) barchart, but rather than using bars, I'd like to use a unicode symbol. Is this possible?

I know how to use a unicode character as a symbol (points); for example:

plot(1,1,pch=-0x0001F3E2, cex=5, col="gray30")

but how can make the symbol substitute the bars?

EDIT:
As suggested by Eric, I'll try to write a minimal reproducible example...

Given variable x:

x <- c(2,3,4,2,1)
barplot(x)

I want to produce a barplot using custom symbols rather than bars. Something like:

plot(1:5,rep(0,5),pch=-0x0001F3E2, cex=x, col="gray30")

The problem is that I am not able to vertical align sysmbols as I can do with text:

plot(1:5,rep(0,5),type="n", ylim=c(0,1),bty="n")
text(1:5,0,"A",cex=c(2,5,3,3,1),adj=c(0.6,0))

So, a sort of solution to my problem, although not ideal, is to use some custom system font with package extrafont.

For example, using font "Destiny's Little Houses" (http://www.dafont.com/destiny-little-hous.font) I am able to produce some nice infographics:

plot(1:5,rep(0,5),type="n",ylim=c(0,1),bty="n")
text(1:5,0.1,"A",cex=c(2,5,3,3,1),adj=c(0.6,0),family="Destiny's Little Houses")

So, rather than having bars I have an image whose size changes according to some variable (using "cex").

This is not ideal, first of all because I'd like to be able to import any image (ex. using the png package).

So, is it possible to:

  1. import an image file and use it as the symbol in plot (rather than one of the available sysmbols using pch)?
  2. Vertical align symbols so that I get a kind of custom barchart?

Thanks António

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
marxco
  • 121
  • 1
  • 3

1 Answers1

0

Here's a somewhat hackish start (might not be helpful as I don't know what your data looks like).

counts <- table(mtcars$gear)
foo <- barplot(counts, col = c("white", "white", "white"), border=c("white"), axes=F, xaxt="n") 
points(foo, counts-.5, pch = -0x0001F3E2, cex=2, pos=3)

Remove , axes=F, xaxt="n" to get the labels and axis back.

Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • Thanks for that. But the real trick is to be able to put the start of the character (in this case the unicode symbol for a building) at the base of the y axis (behave lika a bar in a barplot. The problem is when increasing the size of a symbol with cex it "grows from its centre" (I hope I was clear with this...) – marxco Dec 29 '15 at 19:12
  • Makes sense. have you had a look at [`geom_rect()` in ggplot2](http://docs.ggplot2.org/current/geom_rect.html)? See [ex. here](http://stackoverflow.com/a/14591388/1305688) – Eric Fail Dec 29 '15 at 19:24
  • But from what I get 'geom_rect()' only draws rectangles, by specifying four corners... almost a simplified verions of 'polygons'. – marxco Dec 29 '15 at 21:42
  • 1
    If you share a minimal reproducible example to go along with your question it is much easier for us to help you. Something we can work from and use to show you how it might be possible to solve your problem. I take you know about [this SO post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a great reproducible example in R. – Eric Fail Dec 29 '15 at 22:05