绘制带有重复标签的条形图 [英] Plot a barplot with repeated labels

查看:63
本文介绍了绘制带有重复标签的条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用条形图的形式用重复的x轴标签绘制数据,而不必将值与重复的标签合并.

I would like to plot data with repeated x-axis labels in the form of bar-plot without merging the values with repeated labels.

在示例中,我有一个表 de :

In the example I have a table de:

de <- data.frame(mean=c(10, 2, 3, 1, 4, 5, 3, 9),
                 base=c('A','A','C','G','T','T','T','A'))

我想要一个这样的情节:

And I would like to have a plot like this:

但是当我在R中运行它时:

But when I run this in R:

ggplot(de, aes( y = mean, x =base))+
    geom_bar(stat = 'identity')

这就是我得到的:

它将相同的碱基合并为一列,而我想为 base 的每个值(甚至是重复的值)单独分配一列,如上表所示.

It merges the identical bases into one column, whereas I want a separate column for each value of base, even the repeated ones, as shown in the table above.

推荐答案

简单的方法是:

  • 在基本"列中为As和Ts设置非唯一标签;例如Ax,Ay,Tx,Ty等:
de <- data.frame(mean=c(10, 2, 3, 1, 4, 5, 3, 9), 
  base=c("Ax", "Ay", "C", "G", "Tx","Ty", "Tz", "A"))

然后更改x轴标签:

ggplot(de, aes( y = mean, x =base))+ 
  geom_bar(stat = 'identity') + 
  scale_x_discrete(labels=c("A", "A", "C", "G", "T","T", "T", "A"))

这篇关于绘制带有重复标签的条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆