ML_for_Hackers icon indicating copy to clipboard operation
ML_for_Hackers copied to clipboard

Chapter 3: error executing ggsave to create final plot of results

Open DanBuchan opened this issue 13 years ago • 8 comments

The following command in email_classify.R fails

ggsave(plot = class.plot, filename = file.path("images", "03_final_classification.pdf"), height = 10, width = 10)

Throws this error: Error in seq.default(min, max, by = by) : invalid (to - from)/by in seq(.)

This is using R version 2.15.0 and OSX 10.7.3

DanBuchan avatar May 20 '12 12:05 DanBuchan

Does just calling print(class.plot) produce the same error?

johnmyleswhite avatar May 20 '12 16:05 johnmyleswhite

Yes, print(class.plot) returns the same error too.

I notice also that print(class.res) outputs complete different figures than are printed in the book. Although I assuming this is because the data in the data dir is different atm.

DanBuchan avatar May 20 '12 18:05 DanBuchan

Hmmm. This is quite hard to debug since the error message is so vague. I'll try the code again.

johnmyleswhite avatar May 20 '12 18:05 johnmyleswhite

What version of ggplot2 are you running?

drewconway avatar May 22 '12 13:05 drewconway

My installation reports that I'm using ggplot2_0.9.1

DanBuchan avatar May 22 '12 22:05 DanBuchan

I also has this bug..

Error in seq.default(min, max, by = by) : invalid (to - from)/by in seq(.)

hanfeisun avatar May 26 '12 18:05 hanfeisun

I think that's caused by the "scale_x_log10" function, in the result of easyham2.class, there are some zero-value caused by precison

hanfeisun avatar May 26 '12 20:05 hanfeisun

I had the same problem and agree with hanfelsun that its related to the scale_x_log_10 functions. I was able to get around this by plotting the log of the values for pr.Spam & pr.Ham so avoiding the need to use these functions. ie try this code for your plot instead:

class.plot <- ggplot(class.df, aes(x = log(pr.Ham), log(pr.Spam))) + geom_point(aes(shape = Type, alpha = 0.5)) + stat_abline(yintercept = 0, slope = 1) + scale_shape_manual(values = c("EASYHAM" = 1, "HARDHAM" = 2, "SPAM" = 3), name = "Email Type") + scale_alpha(guide="none") + xlab("log[Pr(HAM)]") + ylab("log[Pr(SPAM)]") + theme_bw() + theme(axis.text.x = element_blank(), axis.text.y = element_blank())

pcp135 avatar Sep 16 '12 20:09 pcp135