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

  • SEARCH
  • Home
  • 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 8230763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:14:30+00:00 2026-06-07T17:14:30+00:00

I’m regularly generating histograms from simulated data, and find it quite helpful to attach

  • 0

I’m regularly generating histograms from simulated data, and find it quite helpful to attach an associated decile table for the data. I’ve been doing this with the addtable2plot function from plotrix. I also find it useful to highlight the row in the table which contains the 50% value – here is an example:

library(plotrix)

# Generate data

mu <- -1.771957
sd <- 0.4716474

foo <- rlnorm(100000, mu, sd)

# Generate decile table
xmax <- .75

max <- format(xmax, digits=2, nsmall=2)

dc <- quantile(foo, probs=seq(0, 1, 0.1))
dps <- c("100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%", "20%", "10%", "0%")
dc <- format(round(dc, digits=2), nsmall=2)

decile <- as.data.frame(dps)
deciles <- as.data.frame(cbind(dps,dc), row.names=FALSE)
colnames(deciles) <- c("Probability", "Rate")
deciles$"Rate" <- as.character(deciles$"Rate")
deciles[1,2] <- "0.00"
deciles[11,2] <- paste(">", max, sep="")

# create a plot
hist(foo, freq=F, xlim=c(0,xmax), breaks=50, col="blue")
top <- max(axis(2))
rect(xleft=(.69*xmax), xright=(1.04*xmax), ybottom=(.615*top), ytop=(.665*top), col="gray91", border=NA)
addtable2plot(x=(1.04*xmax), y=(top), xjust=1, yjust=0, table=deciles, cex=0.82,
          title="Title", hlines=TRUE, vlines=TRUE, bty="o", lwd=1.5, bg="transparent")

As you can see, I’ve been shading simply by adding a colored rectangle underneath the table plot. This takes a lot of tweaking on the xleft, ybottom, and ytop parameters for each histogram.

Is there any way to consistently do this highlighting without all the hassle?
Thanks,

  • 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-07T17:14:32+00:00Added an answer on June 7, 2026 at 5:14 pm

    You mean like this, maybe:

    bg_col <- matrix("white",nrow(deciles),ncol(deciles))
    bg_col[11,] <- "grey"
    
    # create a plot
    hist(foo, freq=F, xlim=c(0,xmax), breaks=50, col="blue")
    top <- max(axis(2))
    rect(xleft=(.69*xmax), xright=(1.04*xmax), ybottom=(.615*top), ytop=(.665*top), col="gray91", border=NA)
    addtable2plot(x=(1.04*xmax), y=(top), xjust=1, yjust=0, table=deciles, cex=0.82,
              title="Title", hlines=TRUE, vlines=TRUE, bty="o", lwd=1.5, bg= bg_col)
    

    enter image description here

    As you can see, I left your rect call in there, just for comparison. There was a short note in ?addtable2plot that said:

    If bg is a matrix of colors of the same dimensions as x, those colors
    will be the backgrounds of the cells. The default is no background
    color.

    which is how I figured out how to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.