R语言给曲线添加标注和点注

    在R语言中,可以使用text(x,y,“标注名称”)来给曲线加标注text,使用point(x,y,col,cex,pch)来给曲线加点注pch。
    下面介绍,在抛物线上,添加标注和点注。
//biaoZhu.R

## 画3条曲线
x <- seq(-10,70,0.01)
y1 <- 1*x^2-50*x+600
y2 <- 1*x^2-40*x+600
y3 <- 1*x^2-30*x+600

## 定义一个二次曲线
f3 <- function(x,a,b,c) a*x^2+b*x+c
## "black" "red" "green3" "blue" "cyan" "magenta" "yellow" "gray"  

plot(y1 ~ x, type = "l",bty="l" ,col="red",xlab = "x", ylab = "y")
lines(y2 ~x, col = 'green')
lines(y3 ~x, col = 'blue')
axis(1,seq(-10,70,10))
axis(2,c(-100,200))
grid()

## 添加标题
title("抛物线")

## 添加标注
tt <- expression(y == ax^2+bx+c)
text(28,1940,tt)


## 显示截距 f(0)
text(6,610,"f(0)")
points(0, 600,col='black',cex = 1.5,pch=16)

pX1 <- seq(10,30,10)

## 在曲线1上选取3个点
pY1 <- f3(pX1,1,-50,600)
points(pX1, pY1,col='red',cex = 1.5,pch=18)

## 在曲线2上选取3个点
pY2 <- f3(pX1,1,-40,600)
points(pX1, pY2,col='green',cex = 1.5,pch=18)

## 在曲线3上选取3个点
pY3 <- f3(pX1,1,-30,600)
points(pX1, pY3,col='blue',cex = 1.5,pch=18)


    效果如下:

图(1) 给抛物线加标注和点注

参考文献:

  1. 公式样式表expression
  2. 点样式pch

猜你喜欢

转载自blog.csdn.net/sanqima/article/details/114264229