我正在尝试绘制这些数据的条形图
我到目前为止写的R脚本如下:
library(ggplot2)
f<-read.table("Coverage_test", sep="\t", header=TRUE)
f$Coverage <- factor(f$Coverage, levels=unique(as.character(f$Coverage)))
g = ggplot(data=f, aes(x=Coverage, y=Variable_counts, group=Form, fill=Type))
+ geom_bar(position="dodge", stat="identity", colour="black")
+ facet_grid( ~ Sample_name, scales="free") + opts(title = "Coverage", axis.text.x = theme_text(angle = 90, hjust = 1, size = 8, colour = "grey50"))
+ ylab("Number of variables") + scale_fill_hue() + scale_y_continuous(formatter="comma")
ggsave("Figure_test_coverage.pdf")
Run Code Online (Sandbox Code Playgroud)
此代码的输出如下:

我的问题是:有没有办法显示基于图的两个变量的行为的差异.每个x轴变量有四个条.我已经选择通过'Type'填充颜色,这显示了'Type'(一个变量)在我的数据中的表现.但我还想展示变量'Form'在我的数据中的表现.我已将它们分组在我的代码'group = Form'中,但无法在实际图形中进行区分(视觉上).这可以通过显示一个变量的不同颜色和另一个变量的不同线型(实线和虚线)在线图中完成.如下所示:
.
我想知道'Form'变量是否可以用不同的颜色显示,或者至少可以在它们各自的条形或任何可能的东西下面命名?任何帮助是极大的赞赏.
谢谢.
我想你想要这样的东西:
ggplot(data=dat, aes(x=Coverage,
y=Variable_counts,
group=interaction(Form,Type),
fill=interaction(Form,Type))) +
geom_bar(position="dodge", stat="identity", colour="black")
Run Code Online (Sandbox Code Playgroud)

编辑
在这里,我会因为条形图和samrt公式表示法而格子化.为了好玩,我使用像主题一样的ggplot latticeExtra.
library(latticeExtra)
barchart(Variable_counts~Coverage|Sample_name,
groups=interaction(Type,Form),
data=dat,stack=F,auto.key=list(columns = 4),
par.settings = ggplot2like(),
axis = axis.grid,
between=list(x=2))
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
2599 次 |
| 最近记录: |