plot_results.r 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. library(ggplot2)
  2. library(cowplot)
  3. library(grid)
  4. library(dplyr)
  5. library(plyr)
  6. library(reshape)
  7. library(plotly)
  8. library(stringr)
  9. sizeAxisLabel <- 22
  10. # Plot environment
  11. env <- read.csv("result_ENV.csv")
  12. # Drop columns that will not be plotted
  13. env$dup_stop <- NULL
  14. env$ddown <- NULL
  15. env$ddown_stop <- NULL
  16. env$pup <- NULL
  17. env$pup_stop <- NULL
  18. env$pdown <- NULL
  19. env$pdown_stop <- NULL
  20. env$obj <- NULL
  21. env_molten <- melt(env, id=c("t"))
  22. pdf("results_Env.pdf", width=10, height=5)
  23. pallete <- c("#89cbaf")
  24. penv <- ggplot(data=env_molten) +
  25. geom_line(aes(x=t, y=value, color=variable), size=2) +
  26. scale_x_continuous("Time (s)") +
  27. scale_y_discrete("Value", limits=c(0, 1), labels=c("0"="False", "1"="True")) +
  28. scale_color_manual("environment",
  29. labels=c("dup"="driver_up","dup_stop"="driver_stop"),
  30. values = pallete) +
  31. theme(axis.title.y=element_blank(),
  32. axis.title=element_text(size=sizeAxisLabel,face="bold"),
  33. axis.text=element_text(size=sizeAxisLabel),
  34. legend.text=element_text(size=sizeAxisLabel),
  35. legend.title=element_text(size=sizeAxisLabel,face="bold"))
  36. penv
  37. dev.off()
  38. # Plot Controller
  39. control <- read.csv("result_Control_sa.csv")
  40. control_molten <- melt(control, id=c("t"))
  41. pdf("results_Control_sa.pdf", width=10, height=5)
  42. pallete <- c("#9699c3",
  43. "#cca956")
  44. pcontrol <- ggplot(data=control_molten) +
  45. geom_line(aes(x=t, y=value, color=variable), size=1) +
  46. scale_x_continuous("Time (s)") +
  47. scale_y_continuous("Value", limits=c(0, 1)) +
  48. scale_color_manual("controller_sa",
  49. values = pallete) +
  50. theme(axis.title.y=element_blank(),
  51. axis.title=element_text(size=sizeAxisLabel,face="bold"),
  52. axis.text=element_text(size=sizeAxisLabel),
  53. legend.text=element_text(size=sizeAxisLabel),
  54. legend.title=element_text(size=sizeAxisLabel,face="bold"))
  55. pcontrol
  56. dev.off()
  57. # Plot power
  58. power <- read.csv("result_power_sa.csv")
  59. power$omega <- NULL
  60. power$theta <- NULL
  61. power_molten <- melt(power, id=c("t"))
  62. pdf("results_power_sa.pdf", width=10, height=5)
  63. pallete <- c("#4f314e")
  64. ppower <- ggplot(data=power_molten) +
  65. geom_line(aes(x=t, y=value, color=variable), size=1) +
  66. scale_x_continuous("Time (s)") +
  67. scale_y_continuous("Value") +
  68. scale_color_manual("power_sa",
  69. labels=c("i"="armature_current"),
  70. values = pallete) +
  71. theme(axis.title.y=element_blank(),
  72. axis.title=element_text(size=sizeAxisLabel,face="bold"),
  73. axis.text=element_text(size=sizeAxisLabel),
  74. legend.text=element_text(size=sizeAxisLabel),
  75. legend.title=element_text(size=sizeAxisLabel,face="bold"))
  76. ppower
  77. dev.off()
  78. # Plot Loop_sa
  79. loop <- read.csv("result_loop_sa.csv")
  80. loop$tau <- NULL
  81. loop_molten <- melt(loop, id=c("t"))
  82. pdf("results_loop_sa.pdf", width=10, height=5)
  83. pallete <- c("#be5440")
  84. ploop <- ggplot(data=loop_molten) +
  85. geom_line(aes(x=t, y=value, color=variable), size=1) +
  86. scale_x_continuous("Time (s)") +
  87. scale_y_continuous("Value") +
  88. scale_color_manual("window_sa",
  89. labels=c("height"="disp"),
  90. values = pallete) +
  91. theme(axis.title.y=element_blank(),
  92. axis.title=element_text(size=sizeAxisLabel,face="bold"),
  93. axis.text=element_text(size=sizeAxisLabel),
  94. legend.text=element_text(size=sizeAxisLabel),
  95. legend.title=element_text(size=sizeAxisLabel,face="bold"))
  96. ploop
  97. dev.off()
  98. # Make multi-grid plot
  99. row_plot <- plot_grid(penv, pcontrol, ppower, ploop, nrow = 4, ncol = 1, align = "v")
  100. save_plot("vertical_plot.pdf", row_plot, nrow = 4, ncol = 1, base_aspect_ratio = 3)