Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.83 KB | None | 0 0
  1. # Script Format for ggplot-ing Calibration Targets and Model Outcomes
  2.  
  3. # This format should get adapted for each kind of calibration plot
  4. # that we want to visualize.
  5.  
  6. # Feel free to share them with me whatever way is easiest -- a zip file
  7. # of R files would be perfectly fine!
  8.  
  9. # dependencies
  10. library(ggplot2)
  11. library(MITUS)
  12. library(dplyr) # I assume we might need to do some re-shaping in dplyr?
  13.  
  14. # Set Location
  15. # loc should be able to vary across the geographies that we have calibrated and
  16. # the rest of the code should still run.
  17. loc <- “US”
  18.  
  19. # Read in Calibration Target and Model Outcomes Dataframes
  20.  
  21. target_df <- readRDS(system.file(loc, “calibration_data”, “specificFileName.rds”, package = “MITUS”)
  22. outcomes_df <- readRDS(system.file(loc, “calibration_data”, “specificFileName2.rds”, package = “MITUS”)
  23.  
  24. # If the target_df or outcomes_df has to be loaded or reshaped differently depending on whether
  25. # loc == 'US' or loc is a state, maybe we will need an if (loc == 'US') { ... } else { ... }
  26. # code block to handle data-loading and reshaping.
  27.  
  28.  
  29. # Data Formatting
  30. # Just let me know if you have any questions or need any help!
  31.  
  32. # Plotting Code
  33. # Just let me know if you have any questions or need any help!
  34.  
  35. # Make sure the ggplot is the last thing in this script so that it's the
  36. # object that gets returned when I put this inside a reactive or a
  37. # function in the Shiny code.
  38. ggplot() +
  39.   geom_bar(data = targets_df, mapping = aes(x = year, etcetera...)) + # changes depending on what format we want
  40.   geom_point(data = outcomes_df, mapping = aes(x = year, etcetera...)) + # changes depending on what format we want
  41.   ggtitle() + # title of the plot
  42.   theme_bw() + # makes the plots a little more professional looking with a white background instead of grey
  43.   other_adjustments_as_necessary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement