Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <code>geom_rect</code>:</p> <pre><code>Vehicles &lt;- structure(list(Road = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L), Start = c(157398137L, 216984017L, 238298694L, 0L, 8794530L, 59852594L, 206737339L, 218695178L, 96301465L, 116345621L, 157398137L, 216984017L, 238298694L, 0L, 8794530L, 59852594L, 206737339L, 3469683L, 96301465L, 116345621L, 157398137L, 216984017L, 238298694L, 0L, 8794530L, 59852594L, 206737339L, 218695178L, 231142027L, 3469683L, 96301465L, 116345621L), End = c(166811234L, 238298694L, 247249719L, 8794530L, 26703134L, 73085123L, 218577503L, 231142027L, 115456078L, 126898764L, 166811234L, 238298694L, 247249719L, 8794530L, 26703134L, 73085123L, 218577503L, 56797911L, 115456078L, 126898764L, 166811234L, 238298694L, 247249719L, 8794530L, 26703134L, 73085123L, 218577503L, 231142027L, 241946296L, 56797911L, 115456078L, 126898764L), Vehicle = c("1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3")), .Names = c("Road", "Start", "End", "Vehicle"), row.names = c(NA, 32L), class = "data.frame") set.seed(42) Vehicles$overspeed &lt;- runif(nrow(Vehicles),0,50) Vehicles$overspeed &lt;- cut(Vehicles$overspeed,c(0,20,30,Inf)) roads &lt;- read.table(text="Road Length 1 529290651 2 249139323 3 298024420",header=TRUE) library(ggplot2) p &lt;- ggplot(Vehicles,aes(xmin=as.numeric(Vehicle)-0.4, xmax=as.numeric(Vehicle)+0.4, ymin=Start,ymax=End,fill=overspeed)) + geom_rect() + facet_grid(Road~.,scales = "free_y") + #ugly hack to get correct road lengths: geom_rect(data=roads,aes(ymin=0,ymax=Length,xmin=0.4,xmax=1.4,fill=NA),alpha=0) + scale_y_continuous(expand=c(0,1)) + xlab("Vehicle") + ylab("Distance") + theme_bw() + scale_fill_manual(values=c("(0,20]"="blue","(20,30]"="yellow","(30,Inf]"="red")) print(p) </code></pre> <p><img src="https://i.stack.imgur.com/0DRR4.png" alt="enter image description here"></p> <p><strong>Edit:</strong> Following @Tyler Rinker's comment, you can reverse the scale like this:</p> <pre><code>p + scale_y_reverse(expand=c(0,1)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload