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 6254231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:08:48+00:00 2026-05-24T14:08:48+00:00

So far, I’ve managed to change the colour a single bar in a histogram

  • 0

So far, I’ve managed to change the colour a single bar in a histogram following the example here

test <- rnorm(100);
h <- hist(test);
b <- cut(1, h$breaks);
clr <- rep("grey", length(h$counts));
clr[b] <- "red";
plot(h, col=clr);

I want to be able to change the colour of histogram bins that are above a certain x-axis value – e.g. that are above 1 in the distribution function in the example. Part of the reason why I am having trouble is that I don’t exactly understand the factor that cut() returns.

  • 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-05-24T14:08:48+00:00Added an answer on May 24, 2026 at 2:08 pm

    Fundamentally you want a logical selector on test not on the cuts.

    Here’s what your cut object looks like:

    > bks <- cut(test,10)
    

    The levels are of type character:

    levels(bks)
    1 “(-2.53,-2.01]” “(-2.01,-1.5]” “(-1.5,-0.978]” “(-0.978,-0.459]”
    [5] “(-0.459,0.0596]” “(0.0596,0.578]” “(0.578,1.1]” “(1.1,1.62]”
    [9] “(1.62,2.13]” “(2.13,2.65]”

    The data is of type numeric:

    > head(as.numeric(bks))
    [1] 5 6 6 6 3 5
    

    Here’s a solution using ggplot2 rather than making the cuts and so forth by hand:

    test <- rnorm(100)
    dat <- data.frame( x=test, above=test>1 )
    library(ggplot2)
    qplot(x,data=dat,geom="histogram",fill=above)
    

    ggplot2 histo

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

Sidebar

Related Questions

As far as I see every time I make a change, for example the
As far as i know it is not possible to do the following in
So far i have the following code, but it doesn't seem to be working,
As far as I know, many nosql stores are written in java, for example
So far I've got the following regex that matches against regular domains but not
Far I've found that giving the iframe a background colour will alter the timeline
As far as I know, it is possible to hide the notification/title bar, once
So far I have been suggesting new features to http://delphi.uservoice.com Since it is managed
So far I have used the following statements in SQLAlchemy to implement table inheritance
Far as best practices are concerned, which is better: public void SomeMethod(string str) {

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.