【发布时间】:2021-07-24 21:25:23
【问题描述】:
我正在为我的一门经济学课程使用 R 绘制图表,我想填写图表的一个区域来表示无谓损失。
以下是我用来制作图表的代码:
rm(list = ls())
library(tidyverse)
housing_market <- ggplot(data.frame(x = c(0,3000)), aes(x = x)) +
stat_function(fun = function(x){2.5-0.001*x}, color = "green", lwd = 1) +
stat_function(fun = function(x){1}, color = "purple", lwd = 1) +
stat_function(fun = function(x){0.70}, color = "blue", lwd = 1) +
ylim(0,2.5) +
annotate(geom = "text", label = "Inverse Demand = 2.5 - 0.001Q", x = 1250, y = 2, size = 4) +
annotate(geom = "text", label = "MSC = 1", x = 500, y = 1.2, size = 4) +
annotate(geom = "text", label = "MPC = 0.70", x = 500, y = 0.5, size = 4) +
ggtitle("Housing Market") +
labs(x = bquote(Q(ft.^2)), y = bquote(P("$"/ft.^2))) +
geom_point(aes(1500,1), color = "black", size = 4) +
geom_point(aes(1800,1), color = "black", size = 4) +
geom_point(aes(1800,0.7), color = "black", size = 4)
housing_market
无谓损失是由点 (1500,1)、(1800,1) 和 (1800,0.7) 创建的三角形。我试过使用geom_rect,但我想不出一种方法让它只填充三角形。任何帮助将不胜感激。
【问题讨论】: