R 轴下的方向箭头

R 轴下的方向箭头,r,plot,ggplot2,R,Plot,Ggplot2,可能重复: 如何使ggplot2或baser生成显示轴方向的箭头 e、 g 这是一个完整的例子,我在微观经济学课上用它来生成供求曲线。请注意这些线,我在其中生成X轴和Y轴。我通常在R工作室工作。它使运行脚本、分析数据结构和查看图形变得更加容易。希望这有帮助 library("ggplot2") library("grid") funcs <- list(function(x) return (200-0.02*x),function(x) return (200-0.04*x),

可能重复:

如何使
ggplot2
或base
r
生成显示轴方向的箭头

e、 g


这是一个完整的例子,我在微观经济学课上用它来生成供求曲线。请注意这些线,我在其中生成X轴和Y轴。我通常在R工作室工作。它使运行脚本、分析数据结构和查看图形变得更加容易。希望这有帮助

library("ggplot2")
library("grid")

funcs <- list(function(x) return (200-0.02*x),function(x) return (200-0.04*x),             function(x) return (10))
#cols <-heat.colors(5,1)
p <-ggplot()+xlim(c(-10,15000))+ylim(c(-10,210))+xlab("Quantity")+ylab("Price")

# Y-axis
p <- p + geom_segment(aes(x=0,y=-10,xend=0,yend=210),         arrow=arrow(length=unit(0.2,"cm")))

# X-axis
p <- p +     geom_segment(aes(x=0,y=0,xend=15000,yend=0),arrow=arrow(length=unit(0.2,"cm")))

# Horizontal segment representing optimal quantity 4750
p <- p + geom_segment(aes(x=0,y=105,xend=4750,yend=105),lty=2, col="gray60")

# Vertical segment representing optimal price i.e $105
p <- p + geom_segment(aes(x=4750,y=0,xend=4750,yend=105), lty=2, col="gray60")

# Marginal Revenue curve label
p <- p + geom_text(aes(x=4750,y=0, vjust=5), col="gray60", label="MR")

# Marginal Cost curve label
p <- p + geom_text(aes(x=15000,y=10, vjust=-1), col="gray60", label="MC")

# Demand curve label
p <- p + geom_text(aes(x=10000,y=0, vjust=4), col="gray60", label="D")

# Optimal Quantity label.
p <- p + geom_text(aes(x=4750,y=0, hjust=1, vjust=1.5), col="gray60", label="Qm", size=3)

# Optimal Quantity
p <- p + geom_text(aes(x=4750,y=0,  hjust=1, vjust=3), col="gray60", label="(4750)", size=3)

# Optimal Price label
p <- p + geom_text(aes(x=0,y=105, hjust=1, vjust=-2.5), col="gray60", label="Pm", size=3)

#Optimal price
p <- p + geom_text(aes(x=0,y=105,  hjust=1, vjust=-1), col="gray60", label="($105)", size=3)

for(i in 1:length(funcs))
  p <- p + stat_function(aes(y=0),fun = funcs[[i]],          arrow=arrow(length=unit(0.2,"cm")))

# Change in marginal cost due to subsidy.
p <- p + stat_function(aes(y=0),fun = function(x) return(5), lty=2,      arrow=arrow(length=unit(0.2,"cm")))
p <- p + geom_text(aes(x=15000,y=5, hjust=-1), col="gray60", label="MC_NEW", size=4)

# Horizontal segment representing optimal quantity 4750
p <- p + geom_segment(aes(x=0,y=102.5,xend=4875,yend=102.5),lty=2, col="gray60")
p <- p + geom_segment(aes(x=4875,y=0,xend=4875,yend=102.5), lty=2, col="gray60")

# Optimal Price label
p <- p + geom_text(aes(x=0,y=105, hjust=.51, vjust=2.5), col="gray60", label="Pm_NEW",     size=3)

#Optimal price
p <- p + geom_text(aes(x=0,y=105,  hjust=.51, vjust=4.0), col="gray60", label="($102.50)", size=3)

# Optimal Quantity label.
p <- p + geom_text(aes(x=4750,y=0, vjust=1.5, hjust=-.5), col="gray60", label="Qm_NEW", size=3)

# Optimal Quantity
p <- p + geom_text(aes(x=4750,y=0,   vjust=3, hjust=-1), col="gray60", label="(4875)",     size=3)
print(p)
库(“ggplot2”)
图书馆(“网格”)

funcs谢谢你的帮助,我想到了
geom_段
方法,但我希望将它们带到绘图区域之外。你的绘图有多复杂?也就是说,您可以使用基本图形来代替吗?使用base(至少对于我们这些不懂网格的凡人来说)可以更容易地把东西放到轴心之外。如果base解决方案更容易实现,那么它可能会起作用