How to get the data back out of an R, ggplot2 or gnuplot plot
The script is gone, the data frame is gone, and the PDF of the plot is all that is left. The points are still in it.
Why the PDF is enough
When a PDF holds the chart as a drawing (most figures in papers do), the values are read from the drawing itself. Nothing is estimated from pixels, so a point is as precise as the file is.
What we measured
- ggplot2: 80 of 80 charts drawn from data we know were read correctly.
- Base R graphics: 79 of 80.
- gnuplot: 80 of 80.
- The kinds tested: bars, grouped bars, lines, smooth curves, scatter plots, log axes, error bars and lines that go below zero.
Steps
- Drop in the PDF of the plot, or the whole report it sits in.
- Each series comes back under its legend name.
- Download Excel or CSV, or copy the table.
Limits
A figure of several panels drawn by R in one go (facets) has not been measured yet: check each panel against the rings.
A plot saved as PNG is a picture. A picture (a screenshot, a scan, a PNG or JPEG) is read by an AI model. Every value is then drawn back on the picture as a ring, so a wrong one is easy to see and to correct in the table.
Questions
My plot was saved with ggsave as a PNG. Can it be read?
Yes, as a picture, which is less exact. If you can run the script again, save a PDF (ggsave("plot.pdf")) and the values are read from the drawing.