0

I have a problem with turning my data into a nice figure. I already turned it into long form, now it looks like this:

Group   ID    variable         value
    1   AD      TAS1R2  -0.000833344
    1   FB      TAS1R2  -0.073365073
    1   KG      TAS1R2   0.415858441
    1   SK      TAS1R2   2.528440629
    1   TF      TAS1R2   0.187186572
    1   BO      TAS1R2   0.078468279
    1   NR      TAS1R2  -0.177461374
    1   RS      TAS1R2   0.885323044
    1   SL      TAS1R2  -0.058843513
    1 SiKo      TAS1R2   0.165354200
    2   AD      TAS1R2   0.040824344
    2   FB      TAS1R2   0.159074753
    2   KG      TAS1R2   0.228949916
    2   SK      TAS1R2   0.261097901
    2   TF      TAS1R2  -0.173072190
    2   BO      TAS1R2   0.025892073
    2   NR      TAS1R2  -0.039772329
    2   RS      TAS1R2   1.213214193
    2   SL      TAS1R2  -0.037842870
    2 SiKo      TAS1R2   9.609456965
    3   AD      TAS1R2   0.006761916
    3   FB      TAS1R2   0.087384138
    3   KG      TAS1R2   2.018923012
    3   SK      TAS1R2   1.735388837
    3   TF      TAS1R2   0.754398704

Code:

cols <- colnames(df[3:9])
d <- melt(df, id.vars= c("Group", "ID"), measure.vars = cols)

When I try to plot it, I get a warning:

ggplot(d, aes(Group, value, col = variable)) +
  stat_summary(fun.y = mean, geom ="point") +
  stat_summary(fun.y = mean, geom = "line", aes(group = Group)) +
  stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2)

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?

I would like to connect the means of the variables across groups with lines. They are portrayed correctly with their dots and error bars, but it seems I either did something wrong when I made "d" or I am missing an argument that tells R how to connect the dots. Any ideas? Help would be greatly appreciated!

Patrick
  • 1
  • 2
  • you should provide a subset of you dataset, just enough to test your code and reproduce the error. Do you have more than one level in Group? – MLavoie Feb 14 '16 at 14:45
  • I have extended the subset to the first 25 entries. Group has 4 levels with the same 10 IDs in each. The idea was to plot the means of the values of each variable per group. Dots and errorbars work just fine, but the groups are timepoints, so a line connecting the respective means to imply continuity should be added. – Patrick Feb 14 '16 at 16:20
  • you summarise your dataset with d2 <- d %>% group_by(Group, variable) %>% summarise(value = mean(value)) and add with geom_line geom_line(data=d2, aes(x=Group, y=value, colour=variable)) – MLavoie Feb 14 '16 at 16:37
  • It worked, thanks a lot :) (Will have to familiarize myself more with ggplot2 and dplyr) – Patrick Feb 14 '16 at 18:22

0 Answers0