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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:23:06+00:00 2026-06-13T08:23:06+00:00

Would appreciate any thoughts on how to make my code or binwidth behave. My

  • 0

Would appreciate any thoughts on how to make my code or binwidth behave. My dataset contains timestamped data points collected every few hours “4”, and daily “24”. I am trying to plot the 4 hour stacked histograms on the left and the 24 hour stacked histograms on the right. Therefore, I want the binwidth on the right to be 6x wider than the left binwidth. But everything I’ve tried with binwidth has not worked. The x axis data, data3$dts appears to be continuous and not discrete but maybe I’m not doing that right.

Important note about the data: Data that gets graphed on the right side, the hours=24 data, has a dts value that is always an integer. Data on the left, the hours=4 data, has non-integer dts values.

             "dts"  "Yes" "No" "Maybe" "hours"  "days"
"258"   15627.668   8       0   1       4   "7 Days"
"259"   15627.832   13      11  18      4   "7 Days"
"260"   15628       34      47  89      4   "7 Days"
"261"   15628       37      47  90      24  "7 Days"
"262"   15628.168   3       0   1       4   "7 Days"
"40"    15571       345     419 674     24  "90 Days"
"41"    15571.5     91      145 130     4   "90 Days"
"42"    15571.668   158     149 284     4   "90 Days"
"43"    15571.832   96      125 260     4   "90 Days"
"44"    15572       55      33  137     4   "90 Days"
"45"    15572       1050    1119 2660   24  "90 Days"

Code with data pulled from pastebin:

library (ggplot2)
library (scales)
library(grid)
library(gridExtra)

color3 <- c("mediumspringgreen","red","grey44")
titles.days <-  c( "7 Days", "90 Days") 
names.facetby <- c ("dts", "hours", "days")

data3 <- read.table ("http://pastebin.com/download.php?i=wUQQUXP4", header=TRUE)
data3.melt <- melt (data3 , id = names.facetby )   
data3.melt$days <- factor (data3.melt$days, levels = titles.days)   #  put the factor in the right order, so the graphs are in the right order

 a <- ggplot     ( data3.melt 
        , aes (       x =  dts  #as.Date( dts , date1970) 
                , y =  value 
                , fill = variable)) +
        opts (axis.text.x=theme_text(angle=0, hjust=1)) +
        scale_fill_manual(values = color3) +
        scale_x_date(labels = date_format("%m/%d\n    %a") ) +
        geom_histogram (stat = "identity", position = "stack", binwidth=6.2) +  
        facet_wrap( days ~ hours, ncol=2, scales="free")            

print(a)        

Current results, showing the right sided graphs with binwidth way too narrow:

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-13T08:23:07+00:00Added an answer on June 13, 2026 at 8:23 am

    @justin’s link to Hadley Wickham’s post has the answer, which is to plot left and right graphs in different layers.

    Updated code that plots correctly with 2 new geom_histogram lines inside the ggplot:

    library (ggplot2)
    library (scales)
    library(grid)
    library(gridExtra)

    color3 <- c("mediumspringgreen","red","grey44")
    titles.days <-  c( "7 Days", "90 Days") 
    names.facetby <- c ("dts", "hours", "days")
    
    data3 <- read.table ("http://pastebin.com/download.php?i=wUQQUXP4", header=TRUE)
    data3.melt <- melt (data3 , id = names.facetby )   
    data3.melt$days <- factor (data3.melt$days, levels = titles.days)   #  put the factor in the right order, so the graphs are in the right order
    
    
    
     a <- ggplot     ( data3.melt 
            , aes (       x =  dts  #as.Date( dts , date1970) 
                    , y =  value 
                    , fill = variable)) +
            opts (axis.text.x=theme_text(angle=0, hjust=1)) +
            scale_fill_manual(values = color3) +
            scale_x_date(labels = date_format("%m/%d\n%a") ) +
    
        # bad idea, good ideas follow   geom_histogram (stat = "identity", position = "stack", binwidth=6.2) +  #, breaks = breaks.x
            geom_histogram (data =  subset(data3.melt, hours == 4),  stat = "identity", position = "stack", binwidth=0.3) + #, breaks = breaks.x
            geom_histogram (data =  subset(data3.melt, hours == 24),  stat = "identity", position = "stack", binwidth=0.9) +    #, breaks = breaks.x
    
            facet_wrap( days ~ hours, ncol=2, scales="free")            
    
    print(a)        # plot the thing
    

    Corrected graph:
    http://imgur.com/9j1Xz

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

Sidebar

Related Questions

I'm trying to make a navigation for my website and would greatly appreciate any
I would appreciate any help on this issue. Lets say I want to load
I'm relatively new to Java and would appreciate any help on this! I have
I would really appreciate any jquery expert help as a method I've used previously,
I would really appreciate any help with the following problem: I need to be
I'm very new to C++ and would really appreciate any and all help. I
I'm new to postgreSQL, so would really appreciate any pointers from the community. I
Would very much appreciate any help or hint on were to go next. I'm
Any help with this problem would be fantastic. I appreciate all contributions! Let us
Any help would be appreciated, I'm trying to convert the code below to C#,

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.