Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205521

How do I plot error bars from a second dataframe of summary stats onto my plotted raw data, ggplot2?

$
0
0

I've got my plot how I like it as far as the raw data is concerned. Basically I want something like a bar chart but instead of a filled in bar you can see the raw data points and their confidence intervals. Right now I have all the plotting from my long-format dataframe (dat) with raw values. I have summary stats and high and low confidence intervals for each point cloud in a separate dataframe (sum_stats)

The original plot call:

dat %>% subset(y_var > 0) %>%
  ggplot(aes(x = x_var, y = y_var, group = Treatment, col = Treatment, shape = Treatment)) +
  geom_point(position = position_jitterdodge(jitter.width = 1.5, dodge.width = 1)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  facet_wrap(~comp_group)

When I tried adding geom_error(data = sum_stats, aes(x=x_var, ymin=ci_low, ymax=ci_high), I got an error

Error in FUN(X[[i]], ...) : object 'y_var' not found

When I take the geom_error() call back out, the plot comes up no problem.

The image below is 2 of the 4 facets of the plot, but without the confidence intervals over the clouds of data points. How do I get the confidence intervals onto each cloud of points? enter image description here


Viewing all articles
Browse latest Browse all 205521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>