Code Monkey home page Code Monkey logo

Comments (1)

R-CoderDotCom avatar R-CoderDotCom commented on August 26, 2024

I also thought about this. Right now the function I developed (not published yet) allows creating budget constraint as in the image below, but not the corresponding indifference curves. The problem is that I can't add the indifference curve from a line in an automatic manner, but add a tanget to a indifference curve, so I'm not sure if this functionality should be added within the indifference function.

budget(rect1, rect2, x = c(3, 5), labels = c("A", "B"))

imagen

What I've tried so far is the following:

# Data
curve2 <- data.frame(Hmisc::bezier(c(1, 3, 9),
                                   c(9, 3, 1)))
x <- curve2$x
y <- curve2$y
plot(x, y)
spl <- smooth.spline(y ~ x)
lines(spl, col = 2)

newx <- 4
pred0 <- predict(spl, x = newx, deriv = 0)
pred1 <- predict(spl, x = newx, deriv = 1)

yint <- pred0$y - (pred1$y * newx)
xint <- -yint / pred1$y

ggplot(curve2, aes(x = x, y = y)) +
  geom_line(data = data.frame(x = x, y = yint + pred1$y * x), color = "red", lwd = 2) +
  geom_line(lwd = 2) + 
  geom_point(data = data.frame(x = pred0$x, y = pred0$y), size = 3, color = "green")

imagen

The previous code can be used to add the tangent of a curve. What do you think? If you have any other suggestions or ideas please let me know.

from econocharts.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.