简体   繁体   English

如何使用R中的plot函数绘制带有点的多条线?

[英]How to plot several lines with points using the plot function in R?

I am new to R and trying to plot a graph using the simple plot() function. 我是R的新手,并尝试使用简单的plot()函数绘制图形。 So, I wrote this code: 因此,我编写了以下代码:

d=read.csv("Nutrition assay example") 
head(d) 
plot(d$Carbs0~d$EAAs0, typ="p", pch=19, ylab="Carbohydrate (g/bee)", xlab="Amino acids (g/bee)") ) lines(d$Carbs0~d$EAAs0) 
lines(d$Carbs1~d$EAAs1, col="red") 
points(d$Carbs1~d$EAAs1, col="red", pch=19)

I get this message: 我收到此消息:

Error in (function (formula, data = NULL, subset = NULL, na.action = na.fail,  :    invalid type (NULL) for variable 'd$Carbs1'

Any help and suggestions? 有什么帮助和建议吗?

You just need to remove the extra parenthesis in your code. 您只需要删除代码中多余的括号即可。

Change this (g/bee)") ) lines 更改此(g/bee)") ) lines

To this code (g/bee)") lines 到此代码(g/bee)") lines

Complete Code 完整的代码

d=read.csv("Nutrition assay example") 
head(d) 
plot(d$Carbs0~d$EAAs0, typ="p", pch=19, ylab="Carbohydrate (g/bee)", xlab="Amino acids (g/bee)")
lines(d$Carbs0~d$EAAs0)
lines(d$Carbs1~d$EAAs1, col="red")
points(d$Carbs1~d$EAAs1, col="red", pch=19)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM