wthimdh
wthimdh

Reputation: 486

how to read data of a matrix from text file in R

I want to read data from a text file in R. File has three columns. First two columns are the indices of a matrix where the last column is the value of corresponding element.

x
1  1  3.02
1  2  2.50
1  3  0.01
2  1  1.34

and so on.. I want to assign column names to x like:

colnames(x) <- c("x","y","value")

I need to create a scatter plot as x values versus y values and data points will be assigned colours depending on the "value". How can I do that in R?

Upvotes: 0

Views: 1023

Answers (1)

wthimdh
wthimdh

Reputation: 486

Easiest way is to use levelplot. Following lines work:

x <- read.table("filename.dat",header=TRUE)
colnames(x) <- c("col1", "col2", "col3")
levelplot(x$col3 ~ x$col1 + x$col2)

Upvotes: 1

Related Questions