Advertisement
Spartrap

Imvexxy/Bijuva 2020 projection

Feb 20th, 2020
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.91 KB | None | 0 0
  1. #
  2. # An R script to visualize the sales trajectory of TherapeuticsMD's Imvexxy/Bijuva
  3. #
  4. # (c) 2019 Germain Garand <germain.garand@laposte.net>
  5. #
  6. # This is for information purposes only. Any calculation performed herein could be
  7. # wrong and/or misrepresent reality. Use at your own risk.
  8. #
  9. # License: Creative Commons BY-NC 2.0
  10.  
  11. library(ggplot2)
  12. library(scales)
  13.  
  14. Sys.setlocale("LC_TIME", "C")
  15.  
  16. a <- c(
  17.   "2019/07/05", "2019/07/12", "2019/07/19", "2019/07/26",
  18.   "2019/08/02", "2019/08/09", "2019/08/16", "2019/08/23", "2019/08/30",
  19.   "2019/09/06", "2019/09/13", "2019/09/20", "2019/09/27",
  20.   "2019/10/4","2019/10/11", "2019/10/18","2019/10/25",
  21.   "2019/11/1","2019/11/8","2019/11/15", "2019/11/22", "2019/11/29",
  22.   "2019/12/6", "2019/12/13", "2019/12/20", "2019/12/27",
  23.   "2020/01/03", "2020/01/10", "2020/01/17", "2020/01/24", "2020/01/31",
  24.   "2020/02/07", "2020/02/14"
  25. )
  26. a <- as.Date(a, "%Y/%m/%d")
  27.  
  28. aa <- seq(as.Date("2020/02/21"), as.Date("2020/12/25"), "week")
  29. a <- c(a, aa)
  30.  
  31. b <- seq(as.Date("2019/07/01"), a[length(a)], "months")
  32.  
  33. imx <- c(
  34.   10250, 8700, 9600, 10250,
  35.   10050,14600, 11515, 10600,11800,
  36.   9900, 9650, 10580, 13111,
  37.   12420,11860,10000,8950,
  38.   9870, 12570, 10400, 10410, 11240,
  39.   8888, 11750, 12050, 11530,
  40.   7896, 9650, 9609, 10057, 8830,
  41.   10240, 9190,
  42.   rep(10000, 8),
  43.   rep(11000, 9),
  44.   rep(12100, 9),
  45.   rep(13310, 9),
  46.   rep(14641, 9),
  47.   rep(15000, 1)
  48. # 620741 scipts in 2020
  49. #rep(10000, 46)
  50. )
  51. bij <- c(
  52.   1000, 750, 1100, 1250,
  53.   1350, 1400, 1200, 1309, 1560,
  54.   1160, 1170, 1450, 1710,
  55.   1700, 1640, 1570, 1550,
  56.   1710, 2010, 1820, 1830, 2080,
  57.   1470, 2080, 2300, 2200,
  58.   1491, 1860, 1881, 1961, 1760,
  59.   1999, 1880,
  60. rep(2090,3),
  61. rep(2299,5),
  62. rep(2528,4),
  63. rep(2781,5),
  64. rep(3059,4),
  65. rep(3365,5),
  66. rep(3702,5),
  67. rep(4072,5),
  68. rep(4480,4),
  69. rep(4928,5)
  70. # 165315
  71. #rep(2000, 46)
  72. )
  73.  
  74. e <- data.frame(a,imx,bij)
  75. names(e) <- c("Week", "Imvexxy", "Bijuva")
  76.  
  77. e$Month <- as.Date(cut(e$Week, breaks = "month"))
  78.  
  79. e$BijNPU <- c(rep(31,13), rep(56,13), rep(66, 13), rep(75, 13), rep(82, 13), rep(86,13))
  80. e$ImxNPU <- c(rep(35,13), rep(51,13), rep(62, 13), rep(66, 13), rep(68, 13), rep(70,13))
  81.  
  82. t = length(a)-1
  83. cwgr = ( ((bij[t]+bij[t+1])/2) / ((bij[1]+bij[2])/2) )^(1/t)-1
  84.  
  85. options(scipen=10000)
  86.  
  87. png("imvexxy_bijuva.png", width=960)
  88. plot(Imvexxy ~ Week, e, type = 'l', col='blue', main="Imvexxy/Bijuva", ylab="Scripts", sub=paste("Bijuva CWGR: ", round(cwgr*100),"%"), col.sub="red")
  89. par(new=TRUE)
  90. plot(Bijuva ~ Week, e, type='s', axes=FALSE, ann=FALSE,col='red')
  91. axis(4, e$Bijuva, col='red', col.axis='red')
  92. legend("top", inset=.05, c("Imvexxy","Bijuva"), fill=c("blue","red"))
  93. dev.off()
  94.  
  95. png("imvexxy_monthly.png", width=1200)
  96. imx_plot <- ggplot(data = e,
  97.   aes(Month, Imvexxy*ImxNPU)) +
  98.   stat_summary(fun.y = sum,
  99.     geom = "bar") +
  100.   scale_x_date(
  101.     labels = date_format("%b"),
  102.     breaks = "1 month") +
  103.   scale_y_continuous(labels = comma) +
  104.   ylab("Scripts*NPU (Dollars)") +
  105.   ggtitle("Imvexxy Projected Revenue")
  106.  
  107. imx_plot_build <- ggplot_build(imx_plot)
  108.  
  109. cnt=0
  110. for(i in imx_plot_build$data[[1]]$y) {
  111.   cnt=cnt+1
  112.   date = b[cnt]
  113.   imx_plot <- imx_plot + annotate("text", x=date,
  114.                 y=i+200000,
  115.                 label=paste("$",i,sep=''),
  116.                 colour="green")
  117. }
  118. print(imx_plot)
  119. dev.off()
  120.  
  121. png("bijuva_monthly.png", width=960)
  122.  
  123. bij_plot <- ggplot(data = e,
  124.   aes(Month, Bijuva*BijNPU)) +
  125.   stat_summary(fun.y = sum,
  126.     geom = "bar") +
  127.   scale_x_date(
  128.     labels = date_format("%b"),
  129.     breaks = "1 month") +
  130.   scale_y_continuous(labels = comma) +
  131.   ylab("Scripts*NPU (Dollars)") +
  132.   ggtitle("Bijuva Projected Revenue")
  133.  
  134.  
  135. bij_plot_build <- ggplot_build(bij_plot)
  136. cnt=0
  137. for(i in bij_plot_build$data[[1]]$y) {
  138.   cnt=cnt+1
  139.   date = b[cnt]
  140.   bij_plot <- bij_plot + annotate("text", x=date,
  141.                 y=i+20000,
  142.                 label=paste("$",i,sep=''),
  143.                 colour="green")
  144. }
  145. print(bij_plot)
  146. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement