Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

R 线


线图

线图使用一条线连接图表中的所有点。

要创建一条线,可以使用 plot() 函数并添加 type 参数,其值为 "l"

示例

plot(1:10, type="l")

结果

自己尝试 »

线颜色

默认情况下,线颜色为黑色。要更改颜色,请使用 col 参数

示例

plot(1:10, type="l", col="blue")

结果

自己尝试 »


线宽

要更改线的宽度,请使用 lwd 参数(1 为默认值,而 0.5 表示缩小 50%,2 表示放大 100%)

示例

plot(1:10, type="l", lwd=2)

结果

自己尝试 »

线型

默认情况下,线条为实线。使用 lty 参数并指定 **0 到 6** 之间的值来指定线格式。

例如,lty=3 将显示虚线而不是实线

示例

plot(1:10, type="l", lwd=5, lty=3)

结果

自己尝试 »

lty 可用的参数值

  • 0 删除线条
  • 1 显示实线
  • 2 显示虚线
  • 3 显示点线
  • 4 显示点划线
  • 5 显示长虚线
  • 6 显示双虚线

多条线

要在图表中显示多条线,请将 plot() 函数与 lines() 函数结合使用

示例

line1 <- c(1,2,3,4,5,10)
line2 <- c(2,5,7,8,9,10)

plot(line1, type = "l", col = "blue")
lines(line2, type="l", col = "red")

结果

自己尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.