简体   繁体   中英

Change the median point geom_point ggplot2 R

I'd like to make the median value in a dotchart by ggplot2 larger to facilitate comparing series.

KO.gyne.gem.face<-c(0.239, NA, NA, 0.058, 0.089, 0.072, 0.150, 0.053, 0.092, 0.076)
KO.worker.gem.face<-c(0.409, 0.564, 0.379, NA, 0.279, 0.272, 0.65, NA, NA, NA)
KO.worker.inv.face<-c(NA, NA, NA, 0.467, 0.506, NA, 0.850, NA, NA, NA)
KO.gyne.inv.face<-c(0.158, 0.054, 0.153, 0.18, 0.268, 0.22, 0.144, 0.244, 0.271, 0.162)
KO.gyne.pure.face<-c(0.313, 0.046, 0.185, 0.048, 0.184, 0.269, 0.056, 0.332, 0.268, 0.279)
KO.cis.inv.face<-c(0.073, 0.069, 0.016, 0.016, 0.036, 0.016, 0.016, 0.016, 0.016, 0.016)
KO.trans.inv.face<-c(0.105, 0.076, NA, 0.069, 0.065, 0.082, 0.537, 0.057, 0.089, 0.016)
KO.synth.cis.C11<-c(0.066, 0.222, 0.074, 0.315, 0.07, 0.199, 0.231, 0.05, 0.222, 0.077)
KO.synth.trans.C11<-c(0.229, 0.246, NA, 0.184, 0.706, 0.196, 0.541, NA, 0.483, 0.127)
KO.synth.cis.C13<-c(0.350, 0.583, NA, 0.542, 0.933, NA, 0.146, 0.472, 0.194, 0.644)
KO.synth.trans.C13<-c(0.050, 0.083, NA, NA, NA, 0.369, NA, NA, NA, 0.483)
KO.synth.inv.face<-c(NA, 0.09, 0.175, NA, 0.118, 0.627, 0.158, 0.094, 0.026, 0.563)
KO.synth.gem.face<-c(0.104, 0.117, 0.115, 0.036, 0.039, 0.113, 0.152, 0.142, 0.024, 0.076)
KO.synth.nicotine<-c(0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008)
KO.times<-data.frame(mget(ls(pattern="KO.")))

ggplot(data=melt(KO.times), aes(x=value, y=variable))+#work on this base
geom_point()

All dots currently have the same size; I'd like to have the median larger, please. Any ideas? Thanks in advance.

Use eg the summary stat to calculate the means. We'll need to flip, since we can only summarize y by x, and not the other way around:

ggplot(data=data.table::melt(KO.times), aes(variable, value))+#work on this base
    geom_point() + 
    geom_point(size = 5, stat = 'summary', fun.y = function(x) median(x, na.rm = TRUE)) +
    coord_flip()

Note that for variables with an even number of observations, the median will not be the value of an actual observation.

在此处输入图片说明

Try this...

KO <- melt(KO.times)
KO$median <- ave(KO$value,KO$variable,FUN=function(x) median(x,na.rm=TRUE))

ggplot(data=KO,aes(x=value, y=variable))+
                 geom_point()+
                 geom_point(aes(x=median),size=3,colour="blue")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM