Lay the graphs on the field and add a line using ggplot

I have such a data frame

data = as.data.frame(data.table::rbindlist(PLOTS))

head(data)
    Y              X     dep_C1

   3.96655960      0     184
  -8.71308460      0     184
 -11.11638947      0     184
  -6.84213562      11    184
  -1.25926609      11    184
  -4.60649529      11    184
   0.27577858      11    184
  11.85394249      20    184
  -0.27114563      20    184
   1.73081284      20    184
   1.78209915      20    184
  11.34305840      20    184
  13.49688263      20    184
  -7.54752045      20    184
 -13.63673286      25    184
  -5.75711517      25    184
   0.35823669      25    184
  -2.45237694      25    184
   0.49313087      0     66
  -9.04148674      0     66
 -15.50337906      0     66
 -17.51445351      0     66
 -10.66807098      0     66
  -2.24337845      5     66
 -13.79929533      5     66
   1.33287125      5     66
   2.22143402      5     66
  11.46484833      10    66
  23.26805916      10    66
   9.07377968      10    66
   4.28664665      10    66

I am trying to create two squares for two values dep_C1and overlay them. I tried with this

ggplot(data, aes(x=factor(X), y=Y, colour = factor(dep_C1))) 
+ geom_boxplot(outlier.size=0,fill = "white") 
+ stat_summary(fun.y=median, geom="line", aes(group=1,colour = factor(dep_C1)),size=2)

These are my problems.

1) Two rectangles are displayed next to each other and do not overlap

2) The command that draws the line between the medians does not work normally: the lines should connect the medians of boxes from one group (only with one box)

3) The values ​​on the x axis are mixed up (the series starts again after 96)

Can someone help me fix these issues? thanks in advance

enter image description here

+1
source share
2 answers

. , position="identity" , , - alpha=0.5. group=factor(dep_C1). :

ggplot(data, aes(x=factor(X), y=Y, colour = factor(dep_C1)))  +
 geom_boxplot(outlier.size=0, fill = "white", position="identity", alpha=.5)  +
 stat_summary(fun.y=median, geom="line", aes(group=factor(dep_C1)), size=2) 

factor(X), . , scale_x_discrete. , - :

scale_x_discrete(limits=seq(min(data$X), max(data$X)))
+2

, X , ; group = interaction(time, group) is aes:

ggplot(data_frame_test, aes(x=time, y=Value, colour = factor(group), group = interaction(time, group)))  +
 geom_boxplot(outlier.size=0, fill = "white", position="identity", alpha=.5)  +
 stat_summary(fun.y=median, geom="line", aes(group=factor(group)), size=2)
0

Source: https://habr.com/ru/post/1612555/


All Articles