0

I am trying to include 3 graphs where the x variables refers to different emotions (coded as 0,1). However, ggplot doesn't allow me to have multiple x values. How can I change this? Or is there a base R version of this I can use?

cdjz_plot <- ggplot(dat2, aes(x = as.factor(normal_positive), y = behavior_ch)) +
  geom_bar(stat = "summary", fun = "mean") +
  scale_x_discrete(labels = c("Negative", "Normal")) +
  stat_summary(geom = "errorbar", fun.data = mean_se, width = 0.2) +
  stat_summary(aes(label = sprintf("%0.2f", round(..y.., digits = 2))),
    geom = "text", fun.data = mean_se, position = position_nudge(y = -0.2)
  ) +
  ylim(0, 1) +
  labs(x = "CDJZ-EP", y = "Probability of behavior change")

Here's how "normal positive" is coded:

dat2$normal_positive <- 0
dat2$normal_positive[
  (dat2$feelings_cbp_calm == 1 | dat2$feelings_cbp_relaxed == 1 |
    dat2$feelings_cbp_happy == 1 | dat2$feelings_cbp_relief == 1 |
    dat2$feelings_cbp_normal == 1) & (dat2$feelings_cbp_angry == 0 &
    dat2$feelings_cbp_anxious == 0 & dat2$feelings_cbp_nervous == 0 &
    dat2$feelings_cbp_stressed == 0)
] <- 1

I tried changing the x variable but it doesnt work

stefan
  • 90,330
  • 6
  • 25
  • 51
debussyn
  • 1
  • 1
  • It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data best shared via `dput()`, e.g. run `dput(dat2[1:10, ])` for the first 10 rows of your data. Also, it would be helpful to clarify what you mean by *ggplot doesn't allow me to have multiple x values.*. Do you get any error messages? – stefan Aug 01 '23 at 15:23

0 Answers0