0

i'm new on R and i have a problem which i really tried to solve but i did not find any clue by myself.

I'm following instructions from "Machine Learning for Hackers" and the last step isn't working or have any google-answers :

What's working :

state.plot<-ggplot(all.sightings, aes(x=YearMonth,y=Sightings)) +  
             geom_line(aes(color="darkblue")) + 
             facet_wrap(~State,nrow=10,ncol=5,scales="free") +
             theme_bw() + 
             scale_color_manual(values=c("darkblue"="darkblue"),guide=FALSE) + 
             scale_x_date(breaks = date_breaks("5 years"), labels = date_format("%Y")) + 
             xlab("Time") + 
             ylab("Number of Sightings") + 
             labs(title="Number of UFO sightings by Month-Year and U.S. State (1990-2010)")

My problem is there :

ggsave(plot = state.plot, filename ="C:\\Users\\l.b\\Downloads\\ufo_sightings.pdf", width = 14, height =8.5)

with the following error :

 Error in layout_base(data, vars, drop = drop) :    At least one layer
must contain all variables used for facetting

I'm using R on Windows.

joran
  • 169,992
  • 32
  • 429
  • 468
Ezay
  • 1
  • 2
  • 1
    You need to provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can see what you're trying to pass to the function. – MrFlick Jun 22 '15 at 14:56
  • A repr.example would be good, but this might be a problem: `c("darkblue"="darkblue")`, try `c("darkblue","darkblue")` – RHA Jun 22 '15 at 15:11
  • @MrFlick Datas come from : https://raw.githubusercontent.com/johnmyleswhite/ML_for_Hackers/master/01-Introduction/data/ufo/ufo_awesome.tsv and the code is here : https://github.com/drewconway/ML-Email-Code/blob/master/01-Using_R/code/ufo_sightings.R#L1. There are some problems in the last link that i have solved so it's kinda hard to give you everything now. The purpose of this is to have 50 graphs (one by US state) about UFO sightings – Ezay Jun 22 '15 at 15:25
  • That data is huge and there are a ton of data manipulation steps which makes for a very bad reproducible example. You should trim things down to only what doesn't work. But, when I ran everything, it worked for me. Well, i did have to change some lines because you must be using an older version of ggplot since you had some deprecated options. I used `ggplot2_1.0.1` and it ran just fine. – MrFlick Jun 22 '15 at 20:30
  • Everything worked but not the last line with ggsave (quoted above). I changed some lines too, in particular the ones with ggplot and the problem may come from here – Ezay Jun 23 '15 at 08:07

0 Answers0