PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] How to make a heatmap with persp function

 June 26, 2022     graph, plot, r     No comments   

Issue

Hello I am trying to draw a 3D production function with different colors.

This production function takes the following form: enter image description here

Where Q represents the production (output), K represents Capital and L represents labor.

I have this:

labour <- seq(1, N, by = 1)
capital <- seq(1, N, by = 1)

cobb_douglas <- function(capital, labour, alpha=0.7, beta=0.25){
  
  capital^(alpha)*labour^(beta)
  
}

production <- outer(capital, labour, cobb_douglas, alpha=0.5, beta=0.5)

persp(labour, capital, production,
      main = "Cobb Douglas Production Function",
      theta = -45, phi = 20,  
      col = "cornflowerblue")

Which display in this graph:

enter image description here

My first question is how can I make the graph have like more colours? Like a heatmap like this one:

enter image description here

My second question is how can I get rid of the arrows in every axis label?

Thanks in advance!


Solution

How about an interactive version?

# Sample data
N <- 100
labour <- seq(1, N, by = 1) / N
capital <- seq(1, N, by = 1) / N
cobb_douglas <- function(capital, labour, alpha=0.7, beta=0.25){
    capital^(alpha)*labour^(beta)
}
production <- outer(capital, labour, cobb_douglas, alpha=0.5, beta=0.5)

library(plotly)
plot_ly(x = ~ capital, y = ~ labour, z = ~ production) %>%
    add_surface(colorscale = "Rainbow")

A (static) screenshot:

enter image description here



Answered By - Maurits Evers
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing