Welcome to Code Sharer, a code gallery for creating, saving and sharing all kinds of code snippets.

R — Plotting a basic graph in R from a ASCII file

Posted On: Sunday, November 2, 2014 at 5:01 AM Last updated: Tuesday, November 4, 2014 at 4:06 PM

test.dat is the name of the ASCII saved in the working directory.

common graph types are; "p" for points, "l" for lines, "b" for both, "c" for the lines part alone of "b", "o" for both ?overplotted?, "h" for ?histogram? like (or ?high-density?) vertical lines, "s" for stair steps, "n" for no plotting.

test<- read.table("test.dat", header=TRUE)
print(test) #prints the ASCII table.
x<- test$x #after the $ is the header title in the ASCII file
y<- test$y #after the $ is the header title in the ASCII file
plot(x, y, main="Test Graph", xlab="X", ylab="y", col="red", type="l", ) #main, xlab and ylab are the main graph, x and y axis labels respectively.

Ryan Bradley-Evans (Admin)

Joined on
Contributed 15 Snips

Get Social and Share