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.
The easiest way is to use R
read.csv to enter the data into R, then use a combination of the
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:
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()
jpeg's you can also save as a
#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()
R is definitely the answer. I would just add to what Rob and Colin already said:
To improve the quality of your plots, you should consider using the Cairo package for the output device. That will greatly improve the quality of the final graphics. You simply call the function before plotting and it redirects to Cairo as the output device.
Cairo(600, 600, file="plot.png", type="png", bg="white") plot(rnorm(4000),rnorm(4000),col="#ff000018",pch=19,cex=2) # semi-transparent red dev.off() # creates a file "plot.png" with the above plot
Lastly, in terms of putting it in a publication, that's the role that
Sweave plays. It makes combining plots with your paper a trivial operation (and has the added benefit of leaving you with something that is reproducible and understandable). Use
cacheSweave if you have long-running computations.
My favorite tool is Python with mathplotlib
- Immediate export from the environment where I do my experiments in
- Support for the scipy/numpy data structures
- Familiar syntax/options (matlab background)
- Full latex support for labels/legends etc. So same typesetting as in the rest of your document!
Specifically, for different file formats like svg and eps, use the format parameter of savefig
An example: input.csv
"Line 1",0.5,0.8,1.0,0.9,0.9 "Line 2",0.2,0.7,1.2,1.1,1.1
import csv import matplotlib.pyplot as plt legends =  for row in csv.reader(open('input.csv')): legends.append(row) plt.plot(row[1:]) plt.legend(legends) plt.savefig("out.svg", format='svg')
Take a look at the sample galleries for three popular visualization libraries:
- matplotlib gallery (Python)
- R graph gallery (R) -- (also see ggplot2, scroll down to reference)
- prefuse visualization gallery (Java)
For the first two, you can even view the associated source code -- the simple stuff is simple, not many lines of code. The prefuse case will have the requisite Java boilerplate code. All three support a number of backends/devices/renderers (pdf, ps, png, etc). All three are clearly capable of high quality graphics.
I think it pretty much boils down to which language are you most comfortable working in. Go with that.
Another option is Gnuplot
Easy is relative. No tool is easy until you know how to use it. Some tools may appear more difficult at first, but provide you with much more fine-grained control once you master them.
I have recently started to make my plots in pgfplots. Being a LaTeX package (on top of
tikz), it is particularly good at making things look good. Fonts will be consistent with the rest of the document and it's much easier to integrate your plots visually. It's not the easiest option to make plots, but it's a rather easy way to make plots that are certainly publication-quality.