Entering edit mode
4.8 years ago
Raheleh
▴
260
I am trying to make a lollipop plot that the dots show median/mean for each variable and the stick lines out of the dots show variance? The code that I wrote is this:
mydata <- df
Avg = rowMeans(df)
SD = apply(df, 1, sd)
Above = ifelse(SD - Avg, TRUE, FALSE)
df$NAME <- rownames(df)
ggplot(df, aes(Avg, NAME, color = Above)) +
geom_segment(aes(x = SD, y = NAME, xend = Avg, yend = NAME), color = "grey50") +
geom_point()
and this is the output:
but I want sth like this image:
Can anyone help me?
Thanks!
Thank you Asaf! could you please tell me what is mean_se in your script? Can you put it in a simple example? I used melt function to put all my variable (15 genes) in one column and all value in the second column. Then I ran this script:
and I got this error:
Can you help me out? Many thanks!
Sorry, forgot to parenthesize
mean_se
. Edited. Take a look atstat_summary
help:https://ggplot2.tidyverse.org/reference/stat_summary.htmlMany thanks Asaf, but still I am getting the same error. I thought maybe it is because of function in the script I change it to fun
now I am getting this error:
any idea? Thanks!
Sorry, I meant quotes not parentheses, also the
function
was wrong, changed tofun.data
(edited the answer again)Many thanks Asaf! I changed the script as you said. Now I am getting this error :-(
This is the structure of my data; do you think there is sth wrong about my data?
try changing to
fun.y
instead offun.data
in the mean partMany thanks Asaf for your time and help. with this script:
Finally I got this image:
But it is not the same as I wanted. how to make the lines horizontal?
Thank you very much Asaf for keep helping me but this time I got this:
I want variable to be in y axis.
coord_flip()
is changing the amount of x with y and vice versa.X should be variable, Y should be value and then use coor_flip to have it opposite.
Yes I already did, but I got the same image as the previous one. The stick lines are vertical not horizontal :-(
Are you sure you have variability in your data?
What do you mean? this is the structure of my data: