1

I am trying to use this chunk of code to create a plot in R. I want to get one frame for each variable in Offensive_Statistic with boxplots per each variable in Jet_Lag_boolean representing the distributions in Measure

    ggplot(data=df_off_plots, aes(y=Jet_Lag_boolean, x=Measure)) + geom_boxplot() +
  xlab("Measurement Value")+
  facet_wrap( ~ Offensive_Statistic, scales="free_y")+
  theme_bw() + ylab(" Number of Time Zones Crossed")  + coord_flip()

I am getting the overall structure correctly but my boxplots are only lines as you can seee here:

I am adding a reproducible dataset:

Data <- data.frame(
  Measure = sample(0:999),
  Jet_Lag_boolean = sample(c("1", "0"), 1000, replace = TRUE),
  Offensive_Statistic = sample(c('OPA', 'OA', 'SLG'), 1000, replace = TRUE)
)

I am getting the same error:

enter image description here

camille
  • 16,432
  • 18
  • 38
  • 60

1 Answers1

1

You got the x & y orders backward

library(ggplot2)

ggplot(data = Data, aes(y = Measure, x = Jet_Lag_boolean)) +
  geom_boxplot() +
  # geom_jitter() +
  facet_wrap(~ Offensive_Statistic, scales = "free_y") +
  theme_bw() + 
  # coord_flip() +
  ylab("Measurement Value") +
  xlab("Number of Time Zones Crossed")

Created on 2019-05-18 by the reprex package (v0.3.0)

Tung
  • 26,371
  • 7
  • 91
  • 115