简体   繁体   中英

ggplot2 clustering in R

can someone point me in the right direction to making a plot like this one w/ ggplot2? even just the function type.

I've been looking around in ggplot2 and can't find anything like this.

I'm assuming that the essential features of the plot are that: a.) the x-axis is categorical, and b.) the x-positions of the points are varied slightly, c.) some summary statistic (I used medians). If that's what you're looking for,

require(ggplot2)
require(plyr)

#define the data
lev <- gl(2, 10, 20, labels=c("I", "II"))
y <- runif(20)
df <- data.frame(lev, y)

#calculate the medians - I'm guessing that's what the horiz lines are?
meds <- ddply(df, .(lev), summarise, med = median(y))

ggplot(df, aes(x=lev, y=y, colour=lev)) + 
  geom_point(position="jitter") +
  theme_bw() +
  scale_colour_manual(values=c("red", "darkblue")) +
  geom_errorbar(data=meds, aes(x=lev, y=med, ymin=med, ymax=med)) 

You can use annotate() to add the numbers and the little bracket if that is important. 在此输入图像描述

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