[R] barplot: add an image in each bar

Jim Lemon jim at bitwrit.com.au
Thu Aug 15 03:26:42 CEST 2013


On 08/15/2013 01:16 AM, Igor Ribeiro wrote:
> Dear all,
> I need to insert an small icon in each bar of a barplot, in a specific
> location (depending on bar's value).
> For example: the first bar has X value of 5. I need to insert an icon at X
> value 3. The second bar has X value of 8. I need to insert an icon at value
> 7.
> I have both vectors with values for the bars and values where I should
> include the icon.

Hi Igor,
You can probably display your "icons" with the rasterImage function in 
the base graphics package. In order to position the images, you will 
need the return value from barplot:

barpos<-barplot(...)

giving you the x positions, and your "values where I should include the 
icon" for the y positions. You will have to specify the position of the 
images in "bottom left/top right" coordinates, so this will depend upon 
the size of the image.

Jim



More information about the R-help mailing list