Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:53:55+00:00 2026-06-07T18:53:55+00:00

I am working on stacked bar plot but i need to assign image here

  • 0

I am working on stacked bar plot but i need to assign image here hand on particular stack.

enter image description here

enter image description here

How can i do this in R.

DF = data.frame(names = c("tomato", "potato", "cabbage", 
                          "sukuma-wiki", "terere"),
                freq=c(7,4,5,8,20))
barplot(as.matrix(DF[,2]), col=heat.colors(length(DF[,2])), 
        legend=DF[,1], xlim=c(0,9), width=2)

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:53:57+00:00Added an answer on June 7, 2026 at 6:53 pm

    Here is a way, how you could do it with grid.

    # libraries
    library(jpeg)
    library(grid)
    
    # a is your image
    a <- readJPG("foo.jpg")
    
    # ypos.img is at which height of the barchart you want to place the image
    ypos.img <- 10
    
    # Create a new polot
    grid.newpage()
    pushViewport(viewport(width=0.9, height=0.9))
    
    # add image
    pushViewport(viewport(yscale=c(0,sum(DF[,2])), xscale=c(0,1), x=0, y=0, width=0.4, height=1, just=c("left", "bottom")))
    grid.raster(a, y=unit(ypos.img, "native"))
    
    # add barplot
    popViewport()
    pushViewport(viewport(x=0.4, y=0, width=0.6, height=1, just=c("left", "bottom")))
    pushViewport(dataViewport(xscale=c(0,2), yscale=c(0, sum(DF[,2]))))
    cols <- heat.colors(length(DF[,2]))
    
    for (i in 1:nrow(DF)) {
     start <- 0 
     if (i > 1) start <- sum(DF[1:(i-1), 2])
     grid.rect(x=0, y=start, width=1, height=DF[i, 2], default.units="native", just=c("left", "bottom"), gp=gpar(fill=cols[i]))
    }
    
    popViewport(2)
    
    # Legend
    pushViewport(viewport(x=0.75, y=0, width=0.25, height=1, just=c("left", "bottom")))
    ypos <- 0.8
    for (i in 1:nrow(DF)) {
     grid.rect(x=0.05, y=ypos, width=0.1, height=0.05, just=c("left", "bottom"), gp=gpar(fill=cols[i]))
     grid.text(DF[i,1], x=0.2, y=ypos, just=c("left", "bottom"))
     ypos <- ypos - 0.05
    }
    
    popViewport()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Stacked Vertical is working fine: http://jsfiddle.net/Q28Aj/1/ But if I change the bar to horizontal
I am creating stacked bar charts on subsets of data using a loop. I'm
I am working on a project and need to add an additional image using
I have a need to render and display charts (bar charts for now, but
I am stacked. My code can not prevent defaut action of submit. This was
I've been working on this for 2 days and I can't figure it out.
I'm trying to get this simple list working, but the ul is closing and
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.