简体   繁体   English

从R中的表绘制数据

[英]Plotting data from a table in R

new to using "R". 刚使用“ R”。 I'm plotting air quality data. 我正在绘制空气质量数据。 I've currently got a table I'm pulling from a file I've designated "air" that looks like so: 我目前有一张要从我指定为“ air”的文件中提取的表格,该表格如下所示:

Ozone   Radiation
   3        4
   7        5
   8        3

The following is my code, but when I ask R to make a scatter plot of it I get this error: 以下是我的代码,但是当我要求R对其进行散点图时,会出现此错误:

Error in xy.coords(x,y,xlabel,ylabel,log) : 'x' and 
'y' lengths differ calls: etc...

This is my code 这是我的代码

air<- read.table("air")

Ozone <- air[1]
Radiation <- air[2]
plot(Ozone,Radiation)

I really want to just plot these two data against each other(preferably in a scatter plot). 我真的只是想将这两个数据相互绘制(最好是在散点图中)。 I know this is an elementary question, but thanks for the attention. 我知道这是一个基本问题,但感谢您的关注。

This code with ggplot will give the plot below. 带有ggplot代码将给出以下图表。

df <- data.frame(
       Ozone = c(3L, 7L, 8L),
   Radiation = c(4L, 5L, 3L)
)

library(ggplot2)
ggplot(df, aes(x = Ozone, y = Radiation)) + geom_point(color = "blue", size = 3)

在此处输入图片说明

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

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