Saturday 15 August 2015

Plotting a visualization of different categories of observation in R -


Using R, I want to plot a map of many observations (where an observation is a specific vehicle given by the registration plate).

To accelerate the distance covered with many different roads, I also want to assume that Want to colorize comments according to the speed of travel (red + 30 mf, yellow-20-30 mf, blue-0-20 mf)

INPUT <

  1. For each vehicle:
    • The road on which it was fast
    • Places for the given street (start and end)
    • Fast range (top to red, yellow or blue)
    • For that which was fast (can be on a road several times) Each street
      • Distance of the road

        Data

          $ Vehicle1 road start end 1 157 398 137 166 811 234 1 216 984 017 238 298 694 1 238 298 694 247 249 719 2 0 8,794,530 2 8,794,530 26,703,134 2 59,852,594 73,085,123 2 206 737 339 218 577 503 2 218695178 231142027 3 96301465 115456078 3 116345621 126898764 $ Vehicle2 Road Start end 1 157398137 166811234 1 216984017 238298694 1 238298694 247249719 2 0 8794530 2 8794530 26703134 2 59852594 73085123 2 206737339 218577503 3 3469683 56797911 3 96301465 115456078 3 116345621 126898764 $ Vehicle3 road start end 1 157 398 137 166811234 1 216984017 238298694 1 238298694 247249719 2 0 8794530 2 8794530 26703134 2 59852594 73085123 2 206737339 21857 7503 2 218695178 231142027 2 231142027 241946296 3 3469683 56797911 3 96301465 115456078 3 116345621 126898764 road length 1 529290651 2 249139323 3 298024420   

        expected output < P> Enter image details here

        Using :

          vehicle < - 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, 3 L, 3 L, 3 L), Start = C (157,398,137 L 21 9 84017 L, 238298694 L, 0 L, 8,794,530 L, 59852594 L 20673733 9 L, 218,695,178 L, 96301465 L, 116,345,621 L, 157,398,137 L, 216 9 84017 L, 238298694 L, 0 L, 8,794,530 L, 598 525 9 4, 20,673,733 9 L, 3469683 l, 96301465 L, 1563398137L, 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, 12 6898764L, 166811234L, 238298694L, 247249719L, 8794530L, 26703134L, 73085123L, 218577503L, 231142027L, 241946296L, 56797911L, 115456078L, 126898764L), Vehicles = c ("1", "1", "1", "1", "1" 2 "," 2 "," 2 "," 2 "," 2 "," 1 "," 1 "," 1 "," 1 "," 1 "," 2 "," 2 "," 2 " "2", "2", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3 Name "C" ("road", "start", "end", "vehicle"), line.Name = c (NA, 32L), square = "data" frame ") set.seed (42) vehicle $ Overspeed & lt; - runif (nrow (vehicle), 0,50) vehicle $ overspeed & lt; - Reduction (vehicles $ overspeed, c (020, 30, Inf)) roads & lt; - read.table (text = "road length 1 529,290,651 2 249,139,323 3 298,024,420", header = TRUE) library (ggplot2) P & lt; - ggplot (Vehicle, AES (xmin = as.numeric (vehicle) -0.4, xmax = as.numeric (vehicle) 0.4, ymin = start, ymax = end, = overspeed) + geom_rect () + facet_grid (road filling , Weighs = "free_y") + #ugly to get the right road length: geom_rect (data = roads, AES (ymin = 0, ymax = length, xmin = 0.4, xmax = 1.4, NA = filling), alpha = 0) + scale_y_continuous + xlab extension of ("c" (0,1)) "vehicle" "(" distance ") + theme_bau () + scale_fill_manual (value = c (" (0,20) "=" blue " , "(20,30)" = "yellow", "(30, inf)" = "red")) print (p)   

         Enter image details here

        edited Do: After the comment of @ Taylor Rinker, you can change this type of scale:

          p + scale_y_reverse (extension = C (0,1))    

No comments:

Post a Comment