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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:26:25+00:00 2026-06-14T08:26:25+00:00

I have a simplified dataframe library(ggplot2) df <- data.frame(wins=c(1,1,3,1,1,2,1,2,1,1,1,3)) ggplot(df,aes(x=wins))+geom_histogram(binwidth=0.5,fill=red) I would like to

  • 0

I have a simplified dataframe

library(ggplot2)
df <- data.frame(wins=c(1,1,3,1,1,2,1,2,1,1,1,3))
ggplot(df,aes(x=wins))+geom_histogram(binwidth=0.5,fill="red")

I would like to get the final value in the sequence,3, shown with either a different fill or alpha. One way to identify its value is

tail(df,1)$wins

In addition, I would like to have the histogram bars shifted so that they are centered over the number. I tried unsuccesfully subtracting from the wins value

  • 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-14T08:26:26+00:00Added an answer on June 14, 2026 at 8:26 am

    1) To draw bins in different colors you can use geom_histogram() for subsets.

    2) To center bars along numbers on the x axis you can invoke scale_x_continuous(breaks=..., labels=...)

    So, this code

    library(ggplot2)
    df <- data.frame(wins=c(1,1,3,1,1,2,11,2,11,15,1,1,3))
    cond <- df$wins == tail(df,1)$wins
    
    ggplot(df, aes(x=wins)) +
      geom_histogram(data=subset(df,cond==FALSE), binwidth=0.5, fill="red") +
      geom_histogram(data=subset(df,cond==TRUE), binwidth=0.5, fill="blue") +
      scale_x_continuous(breaks=df$wins+0.25, labels=df$wins)
    

    produces the plot:

    enter image description here

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

Sidebar

Related Questions

I have a problem in a VB.Net class library which I have simplified greatly
I got following data frame (simplified here): H2475 H2481 H2669 H2843 H2872 H2873 H2881
I am trying create a data.frame from which to create a graph. I have
I have simplified my code to this internal class Program { private static void
I have the following methods in an enum helper class (I have simplified it
I am getting this error on a website I'm working on, I have simplified
I have these simplified types: public class DataBean extends ZZZZZ { public String name;
I have a (simplified) table consisting of three columns: id INT PRIMARY KEY NOT
I have this (simplified) class: public class StarBuildParams { public int BaseNo { get;
Names and objects have been simplified for clarity's sake. The basic concept remains the

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.