PDA

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



ganna10
August 10th, 2012, 03:01 PM
Hi,

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!
Thanks,
Jane

PC_load_letter
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?

Best.

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

Thanks,
Jane

PC_load_letter
August 14th, 2012, 10:37 PM
Jane,
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:
https://www.google.com/search?q=ggplot2+bug+small+values&sugexp=chrome,mod=15&sourceid=chrome&ie=UTF-8

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.

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