r - ggplot2: dot plot with repeated measures and means -
that's first question in here, please, don't angry if anything..
the point is:
i have several timepoints (graft, day 0, day 60 etc...) , several samples each. samples have been measured , have several numbers each timepoint. i'd make dot plot placing dots according measured values (on y-axis) grouped timepoints (on x-axis). i'm totally new ggplot, i've succesfully created plot. examplary data.frame , code plot looks like:
data=data.frame(value=1:30, time=rep(c('d0', 'd1', 'd2'), each=10)) str(data) 'data.frame': 30 obs. of 2 variables: $ value: num 1 2 3 4 5 6 7 8 9 10 ... $ time : factor w/ 3 levels "d0","d1","d2": 1 1 1 1 1 1 1 1 1 1 ... g=ggplot(data=data, aes(x=time, y=value)) g+geom_point()
but have no idea how add short lines mark median values each timepoint... guess should use geom_segments somehow, don't know how deal x, xend, y , yend in case... advise me smth?
thank's all!
this sort of thing can use stat_summary
geom
of choice. example, add median point
using long dash symbol , changing size looks ok.
ggplot(data = data, aes(x = time, y = value)) + geom_point() + stat_summary(fun.y = "median", geom = "point", pch = "_", size = 25)
another alternative use crossbar
or errorbar
geom
, have set ymin
, ymax
these. can set aesthetics ..y..
in order set them same y
variable. changing width
changes how long lines are.
ggplot(data = data, aes(x = time, y = value)) + geom_point() + stat_summary(fun.y = "median", geom = "crossbar", mapping = aes(ymin = ..y.., ymax = ..y..), width = .25)
Comments
Post a Comment