0

I have a df that looks like this:

   ID Genotype Time10min  N        mean          sd           se          ci
43  1   k_DMSO        43 10 0.029318750 0.009793853 0.0030970883 0.007006100
44  1   k_DMSO        44 10 0.008825716 0.005164837 0.0016332648 0.003694702
45  1   k_DMSO        45 10 0.008466507 0.002879642 0.0009106228 0.002059972
46  1   k_DMSO        46 10 0.005871386 0.003848483 0.0012169970 0.002753039
47  1   k_DMSO        47 10 0.003126562 0.004755841 0.0015039288 0.003402123
48  1   k_DMSO        48 10 0.005546801 0.003725496 0.0011781053 0.002665059

I want to plot a graph with "mean" on the y-axis and "Time10min" on the x-axis.

For this I want the mean across all means within a group specified by "Genotype" using this function:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)

I get one line per group as mean which is what I want.

I then want to add a geom_ribbon based on sem.

I tried the following 2 options:

  ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  geom_ribbon(aes(group=Genotype, fill=Genotype,ymin=mean-se, ymax=mean+se), alpha=0.5)

This gives me a very disrupted ribbon looking something like this: graph

The other options that worked before updating my R is this one:

 ggplot((data_all), aes(x=Time10min, y=mean))+
  stat_summary(aes(group=Genotype, color=Genotype), fun=mean, geom="line", size=2)+
  stat_summary(aes(group=Genotype, fill=Genotype),geom="ribbon",fun.data = mean_cl_boot, alpha= 0.5)

Now I keep getting an error like this:

Warning: Computation failed in `stat_summary()`:

The data types are:

'data.frame':   36100 obs. of  8 variables:
 $ ID       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Genotype : Factor w/ 10 levels "w_DMSO","h_DMSO",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Time10min: int  1 2 3 4 5 6 7 8 9 10 ...
 $ N        : num  10 10 10 10 10 10 10 10 10 10 ...
 $ mean     : num  0.026 0.0341 0.0312 0.0173 0.0114 ...
 $ sd       : num  0.00801 0.0047 0.01085 0.01521 0.00868 ...
 $ se       : num  0.00253 0.00149 0.00343 0.00481 0.00274 ...
 $ ci       : num  0.00573 0.00336 0.00776 0.01088 0.00621 ...

Please, can someone help me to get a nice ribbon onto this plot?

Thank you!

Tahnee
  • 77
  • 5
  • 1
    You may need to include more of your data. When I run your code with the data you provided, I get a nice ribbon around the mean line as expected. – Allan Cameron Mar 04 '22 at 09:59
  • Mmmmhh which of these options work for you? The stat_summary or the geom_ribbon one? I am not too sure what else to include in terms of information... – Tahnee Mar 04 '22 at 10:49
  • I solved it - thinking that you run it fine it turns out I did not have the Hmisc package installed even thought I did not get an error saying so - thank you either way!! – Tahnee Mar 04 '22 at 10:58

0 Answers0