2

I tried to apply economic order quantitz which I need to visualize. However, I would like to indicate equilibrium points in economic order quantity where I have overlapped lines. Unfortunately,

eq <- xx[which.min(abs(xx$holdingcost - xx$orderingcost)), ]

this part is not working exaclty. It does not put point at equilibrium point everytime.

enter image description here

Here is the code.

ui.R

  library(shiny)

  shinyUI(pageWithSidebar(

  headerPanel("Economic Order Quantity"),

   sidebarPanel(
 h3(strong("Parameters",style = "color:black")),
 br(),

  sliderInput("D", "Annual Demand Quantity (D)",min = 1, max = 1000, step= 10, value = 500),
  sliderInput("S", "Ordering Cost (S)",min = 1, max = 1000, step= 1, value = 500),
  sliderInput("h", "Holding Cost (i)",min = 0.01, max = 1, step= 0.01, value = 0.3),
  sliderInput("C", "Cost per unit (c) ",min = 1, max = 500, step= 1, value = 150)

  ),

   mainPanel(

         plotOutput("plotgraph1"))))

server.R

 library(shiny)
 require(ggplot2)
 require(scales)

shinyServer(function(input, output) {

output$plotgraph1<-renderPlot({

    Q<-((2*input$D*input$S)/(input$h*input$C))^(1/2)
    xdata <- seq(1,Q*(1.7),1)

    HCOCdata <- matrix(1,1)
    HCdata <- matrix(1,1)
    OCdata <- matrix(1,1)

  for (i in xdata) {

      OC<-(input$D/i)*input$S
      HC<-(i/2)*input$h*input$C
      HCOC<-OC+HC
      HCdata[i]<- HC
      OCdata[i]<- OC
      HCOCdata[i]<- HCOC
}


    HCOCcost <- data.frame(HCOCcost=HCOCdata)
    holdingcost <- data.frame(holdingcost=HCdata)
    orderingcost <- data.frame(orderingcost=OCdata)

    Quantity <- xdata
    CostType <- c("HCOCcost","holdingcost","orderingcost")
    xx<-cbind(Quantity,HCOCcost,holdingcost,orderingcost)


    y <- ggplot(xx, aes(x=Quantity, y=Cost), group = xx , colour=xx ) + 
        geom_line(size=1,aes(y=HCOCcost, colour = "HCOCcost"), linetype=2) + geom_line(size=1,aes(y=holdingcost, colour = "holdingcost")) + geom_line(size=1,aes(y=orderingcost, colour = "orderingcost")) 

    eq <- xx[which.min(abs(xx$holdingcost - xx$orderingcost)), ]
    y1 <- y + scale_y_continuous(limits=c(0, max(HCOCcost)/10),labels=comma) + geom_point(data = eq, aes(y = holdingcost), size = 4 , color="red") 
    y1 })})
Hack-R
  • 22,422
  • 14
  • 75
  • 131
can.u
  • 515
  • 1
  • 4
  • 12
  • 1
    this might help http://stackoverflow.com/questions/20519431/finding-point-of-intersection-in-r – MLavoie Feb 02 '16 at 09:57
  • Your code snippet finds a point that's closest to the intersection, whereas the intersection itself can be elsewhere. Check the link above, it is indeed what you need. – tonytonov Feb 02 '16 at 13:32

0 Answers0