View Full Version : [SOLVED] R plotting: ggplot output differing from plot output for same dataset

August 10th, 2012, 03:01 PM

I am starting to use R to create data plots using the ggplot2 package rather than the standard plot function that comes with R.

The data is a set of mixing ratios of NO against time, hence very small values of NO but that change throughout the range of time values.

To get use the standard plot function I use:
plot(time, NO)

and the output is a plot that has maxima & minima throughout the plot.

To use ggplot I write:
ggplot(data=plot_data, aes(x=time, y=NO)) + geom_point() + coord_cartesian(ylim=c(0, 5e-12))

and the resulting output is a straight-line graph with all the y-values being 0.

I am just wondering now whether the fact that all the data input values for NO are in scientific notation (i.e. 6.6e-14).

Any help is appreciated!

August 10th, 2012, 07:50 PM
Could you please elaborate more, what is NO? Also, can you attach the data set so I can try this on my setup and confirm the discrepancy if there is any?


August 13th, 2012, 10:21 AM
NO is Nitrogen Oxide, the data is attached.


August 14th, 2012, 10:37 PM
It seems it's a bug in ggplot2, it doesn't scale correctly if the y-values are too small, it has been fixed in 0.9.0 but apparently it came back, here:

There is a workaround by scaling your data, here:

s <- 1E15
ggplot(NO_time, aes(time, NO*s)) + geom_point() + scale_y_continuous(labels=function(x) as.character(x/s)) + ylab("Y")

With this code I get this plot which is the same as the one I get from the standard plot.

August 15th, 2012, 09:08 AM
That is fantastic! Works like a charm :-)