【发布时间】:2021-05-17 17:33:00
【问题描述】:
我有
chr totgenes FST>0.4 %FST>0.4 exFST>0.4 %exFST>0.4 inFST>0.4 %inFST>0.4 chrtotlen
1 1457 49 3.36307 73 5.0103 54 3.70625 114375790
1A 1153 49 4.24978 72 6.24458 48 4.1630 70879221
2 1765 80 4.53258 132 7.47875 96 5.43909 151896526
3 1495 33 2.20736 56 3.74582 35 2.34114 111449612
4 953 58 6.08604 89 9.33893 56 5.87618 71343966
4A 408 9 2.20588 17 4.16667 11 2.69608 19376786
5 1171 52 4.44065 81 6.91716 44 3.75747 61898265
6 626 48 7.66773 62 9.90415 47 7.50799 34836644
7 636 8 1.25786 24 3.77358 8 1.25786 38159610
8 636 24 3.77358 28 4.40252 27 4.24528 30964699
9 523 18 3.44168 23 4.39771 21 4.0153 25566760
我想做一个条形图,其中 y 是 cols FST>0.4 exFST>0.4 inFST>0.4 的值,x 是 chr col,条形的宽度是 chrtotlen。
我正在尝试使用
data<-read.table("realBFWBM_noNAs.fst.totgenesChrcp", sep="\t", header = TRUE)
myVector <- c("chr", "FST.0.4", "exFST.0.4", "inFST.0.4", "chrtotlen")
melted <-melt(data[,myVector], id = c("chr", "chrtotlen")
ggplot(melted, aes(x=as.factor(chr), y=value, width=chrtotlen))+
geom_bar(aes(fill=variable), stat = "identity")+
theme(
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
legend.title = element_blank(),
legend.position = c(0.8, 0.8),
axis.title.x=element_text(size=20),
text = element_text(size=20),
axis.text.x = element_text(size=20),
panel.background = element_blank(),
axis.text.y = element_text(size=20)
)
我也收到错误"position_stack requires non-overlapping x intervals"
在基础 R 方面取得了一些进展,但仍有工作要做,因为轴的行为不符合预期。
data<-read.table("realBFWBM_noNAs.fst.totgenesChrcp", sep="\t", header = TRUE)
myVector <- c("chr", "FST.0.4", "exFST.0.4", "inFST.0.4", "chrtotlen")
counts = data[,myVector]
par(xpd = TRUE, mar = c(4,4,2,2))
invisible(sapply(2:4, function(x)
barplot(counts[, x], as.vector(counts$chrtotlen), axes = FALSE, axisnames = FALSE,
#border = 0.5,
density = x + 5,
angle = x ^ 5,
space=0,
axis.lty = 1, ylim = c(0, 150),
add = ifelse(x == 2, FALSE, TRUE))))
axis(2, at = seq(0, 100, 150), labels = seq(0, 100 , 150))
axis(1, at = barplot(counts), labels = colnames(counts))
【问题讨论】:
-
在
geom_bar尝试position = "dodge"。我没有看到直方图代码,只有条形图,没有图重叠。 -
是的,这是我过去使用不同数据绘制的另外两个图。我刚刚上传以举例说明我要在这里绘制的内容。我也不知道我是否应该在这里为我的目的使用 geom_bar 或 geom_histogram。
-
看来你想要
geom_bar和geom_histogram。试试看,但是设置透明度alpha = 0.2或者其他小于等于0.5的值。 -
我不确定,但你的宽度很大?!
-
是的,它可以成比例(chrtotlen/ 1000000)。不需要是绝对数。但我不认为这是造成问题的原因。