如何显示组内连续数据但组间比较

How to show a within-group continuous data but compare between groups

我有一个名为 ret1 的数据框,如下所示:

 chr    binRight    Means
 chr1   1.20e+07    25.320212
 chr1   2.40e+07    30.875749
 chr2   1.60e+07    48.952099
 chr2   2.80e+07    41.356140
 chr2   6.00e+07    20.078314
 chr3   2.20e+07    37.107468
 chr3   3.40e+07    38.257566
 chr3   9.60e+07    38.381219
 chr3   1.08e+08    30.218046

我想创建一个直方图,将 Means 列绘制为按 chr 分组的连续图,这样我就可以看到例如 chr1 的每个 binRight 的每个均值,然后是 chr2 的每个 binRight 的每个均值等同轴。

理想情况下,我希望它看起来像一种图形均衡器直方图,如果有人也知道该怎么做的话。

我试过了

p = ggplot(ret1, aes(x=ret1$binRight)) + geom_histogram(ret1$Means) +
p + facet_grid(chr ~ .)

但这给了我每个字符的计数和 x 轴上的均值,虽然我喜欢绘图的外观和字符的分离方式,但我需要 x 轴上的 binRight 和 y 上的均值情节的轴。

更新:

利用我学到的知识,这应该可以为那里的人们提供一些不错的情节:

#Grouping the data across binRight:
library(dplyr)
ret1 <- df %>%
  group_by(chr, binnum = (leftPos) %/% 12000000) %>%
  summarise(Means = mean(Means)) %>%
  mutate(binRight = (binnum+1) * 12000000) %>%
  select(binRight, Means)

#Convert chr column to numeric by stripping out the "chr"
ret1$chr<-as.numeric(gsub("chr","",ret1$chr))


#Doing the plot
d<- ggplot(ret1, aes(x=as.numeric(binRight),y=as.numeric(Means)),colour=Means) + 
   geom_bar(stat = "identity",aes(fill=Means)) +
  ggtitle("My plot")+
  xlab("Genomic locus") +
  ylab("Raw read counts") +
  theme(axis.text.y=element_text(size=10)) +
  theme(axis.title=element_text(size=14))+
  theme(plot.title=element_text(face="bold", size=20)) +
  scale_y_continuous(breaks=c(0, 80)) +
facet_grid(chr ~ .) 
d +scale_fill_gradient(limits = c(0, 80), low = "green", high = "red").

是这样的吗?

p = ggplot(df, aes(x=binRight)) + geom_histogram(aes(y = Means),stat = "identity")
p + facet_wrap(~chr)