What is the easiest way to create publication-quality plots under Linux?

We may assume that we have CSV file and we want a very basic line plot with several lines on one plot and a simple legend.

Answer

The easiest way is to use R

Use read.csv to enter the data into R, then use a combination of the plot and line commands

If you want something really special, then look at the libraries ggplot2 or lattice.

In ggplot2 the following commands should get you started.

require(ggplot2)
#You would use read.csv here
N = 10
d = data.frame(x=1:N,y1=runif(N),y2=rnorm(N), y3 = rnorm(N, 0.5))
p = ggplot(d)

p = p+geom_line(aes(x, y1, colour="Type 1"))
p = p+geom_line(aes(x, y2, colour="Type 2"))
p = p+geom_line(aes(x, y3, colour="Type 3"))
#Add points
p = p+geom_point(aes(x, y3, colour="Type 3"))
print(p)   

This would give you the following plot:

Line plot http://img84.imageshack.us/img84/6393/tmpq.jpg

Saving plots in R

Saving plots in R is straightforward:

#Look at ?jpeg to other different saving options
jpeg("figure.jpg")
print(p)#for ggplot2 graphics
dev.off()

Instead of jpeg‘s you can also save as a pdf or postscript file:

#This example uses R base graphics
#Just change to print(p) for ggplot2
pdf("figure.pdf")
plot(d$x,y1, type="l")
lines(d$x, y2)
dev.off()

Attribution
Source : Link , Question Author : Łukasz Lew , Answer Author : csgillespie

Leave a Comment