R language to add annotations and points to curves

    In R language, you can use text (x, y, "label name") to add text to the curve, and use point (x, y, col, cex, pch) to add pch to the curve.
    The following introduces, adding annotations and points on the parabola.
//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)


    The effect is as follows:

Figure (1) Add annotations and points to the parabola

references:

  1. Formula style sheet expression
  2. Point style pch

Guess you like

Origin blog.csdn.net/sanqima/article/details/114264229