2

I generated the histogram with the following code:

# Load Data
file <- "SharedData.csv"
data <- read.csv(file,header = TRUE,sep = ",")

## Bin Levels
data$xLevel <- cut(data$xLevel,
                    breaks = quantile(data$xLevel,(0:5)/5),
                    labels = paste("Quant",1:5,sep = "."),
                    include.lowest = TRUE,ordered_result = TRUE)

# Histogram 
g <- ggplot(data, aes(x=xTime,color = xLevel)) + 
    geom_histogram(aes(y=..density..),      
                   binwidth=100)
g  

enter image description here

How do I create the above histogram with an x axis that goes from 0-300 and from 1500-2400, but not include 300-1500? The unit here is military time.

Data: https://www.dropbox.com/s/e5gaym7dhefs04e/SharedData.csv?dl=0

JHall651
  • 427
  • 1
  • 4
  • 15
  • 1
    Please produce a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). It helps in recreating the problem. And add an`!` in front of image link to appear in question itself. – narendra-choudhary Dec 11 '15 at 23:36
  • Share some data? Editing the axis directly will be difficult - an easy solution would be to add an indicator column for if your data is in the 0-300 or 1500-2400 range and then just facet. – Gregor Thomas Dec 11 '15 at 23:36
  • could you include your data so we can have a look at them. – MLavoie Dec 11 '15 at 23:36
  • @Narendra there's a reputation threshold below which users can't post images. High-rep users will typically just edit them in. – Gregor Thomas Dec 11 '15 at 23:36
  • Very sorry for the not making it reproducible, this is my first post and I am working on it. I'll figure out how to share the data momentarily. – JHall651 Dec 11 '15 at 23:43
  • Ok, hopefully that post is a little more helpful. Thanks for your help guys! – JHall651 Dec 11 '15 at 23:54

1 Answers1

4

According to https://groups.google.com/forum/#!topic/ggplot2/jSrL_FnS8kc and Using ggplot2, can I insert a break in the axis? it does not seem to be possible. you can plots 2 graphics instead

first create a new column splitting the data in two

data$Block <- ifelse(data$xTime <=500, "A", "B")

and then plot the graphics

library(scales)
# Histogram 
g <- ggplot(data, aes(x=xTime,color = xLevel)) + 
    geom_histogram(aes(y=..density..),      
                   binwidth=100) + facet_grid(.~Block, scales = "free_x")
g

enter image description here

Community
  • 1
  • 1
MLavoie
  • 9,671
  • 41
  • 36
  • 56