简体   繁体   中英

Create Scatterplot in R from CSV

I have the following CSV document (3 columns, 1 header line, 10 data lines):

Artikelname,Anzahl Zeichen,Anzahl Fehler
Sport/Ski alpin,5459,42
People,2302,20
Nationale Politik,4012,43
Reportage ueber die Lebensmittelindustrie,11202,101
Wirtschaft,3192,22
Interview,2989,21
Sport/Tennis,1509,14
Filmkritik,2498,65
Regionalpolitik,3987,32
Mali-Reportage,10782,91

I now wish to plot the second column on the x-Axis and the third column on the y-Axis of a scatterplot in R.

getwd()
file <- "[filepath]"
data <- read.csv(file, skip = 1) # skip header line
data                             # print the data into the console

plot(data[2],data[3])

I believe it is because my data is not of the correct type yet, but I don't have any idea how to fix this.

First of all, remove skip=1 . Your current code uses the first line of data as the column names instead of data. After reading the data correctly, you want

plot(data[,2],data[,3])

or perhaps more simply

plot(data[,2:3])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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