-1

Why when I use facet_wrap with the function below, I get null outputs for the graphs. A picture of what is going on is attached. The graphs are smushed together and I cannot see any data points. What is going on?

Image

I have covered up titles because of confidential.

There will be 100 or so facets.

data <- read.csv(data.csv)
data$DateTime <- as.POSIXct(data$DateTime,format ='%m/%d/%Y %r')
data <- data %>% mutate(Person = ifelse(Person == 1, "Person 1", "Person 2"))
data %>% 
  filter(Size %in% c('S','M')
         ) %>%
  arrange(LargePerson) %>%      
   ggplot(aes(x = DateTime,y = Price)) +
    geom_point(
               aes(colour = Person)) + 
    scale_colour_manual(values = c("Person 1" = "blue", "Person 2" = "black")) +
    facet_wrap(~ID,scales = "free",ncol=2) + labs(x = "Date") +
    scale_x_datetime(breaks = date_breaks("2 days"),labels = date_format("%m/%d/%y")) +
    theme(axis.text.x = element_text(angle = 90,vjust = 0.5),
          legend.position="bottom"
    )
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 2
    Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Nov 07 '18 at 19:51
  • Hard to tell what's causing the problem without a sample of the data. Can you reproduce the problem with fake data and share that? – iod Nov 07 '18 at 19:51
  • It is hard to tell without a reprex... but I would start by not assigning `data` over `data` – FMM Nov 07 '18 at 19:53
  • 4
    Although, at a guess, I'd say with 100 facets you just don't have enough room. R is trying to fit all the facets into the available window, and there's just not enough room. Try, for example, to plot into a png(height=10000), and see if that solves it. – iod Nov 07 '18 at 19:54

1 Answers1

1

I did some playing around and I think it's probably what I said in my comment: 100 facets just don't fit into the space allotted for the image. The thing that gets squished is the graph itself, not the surrounding elements (like titles etc). For example, here's some fake plots at 50 facets:

df<-data.frame(group=apply(expand.grid(LETTERS,LETTERS),1,paste0,collapse="")[1:50],x=runif(50),y=runif(50))
ggplot(df, aes(x,y))+geom_point() +facet_wrap(~group,ncol=2)

enter image description here

And here's the same plot, with the same code, with the height of the PNG set to 10,000:

enter image description here

iod
  • 7,412
  • 2
  • 17
  • 36