通过为R中每个条形图的不同段分配名称来使直方图更清晰 [英] Make a histogram clearer by assigning names to different segments of each bar in R

查看:68
本文介绍了通过为R中每个条形图的不同段分配名称来使直方图更清晰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含两列和19行的数据框(请参见下文);左列是细胞系的名称,右列是基因ZEB1在相应细胞系中的表达.

Assume that I have a data frame with two columns and 19 rows (see below); The left column is the name of cell lines and the right one is the expression of gene ZEB1 in corresponding cell line.

    CellLines   ZEB1
    600MPE  2.8186
    AU565   2.783
    BT20    2.7817
    BT474   2.6433
    BT483   2.4994
    BT549   3.035
    CAMA1   2.718
    DU4475  2.8005
    HBL100  2.6745
    HCC38   3.2884
    HCC70   2.597
    HCC202  2.8557
    HCC1007 2.7794
    HCC1008 2.4513
    HCC1143 2.8159
    HCC1187 2.6372
    HCC1428 2.7327
    HCC1500 2.7564
    HCC1569 2.8093

我已使用以下简单代码对此数据绘制了直方图:

I've drawn a histogram for this data using simple code below:

hist(Heiser$ZEB1[1:19], breaks=50, col="grey")

它给出了直方图,直方图的x轴是基因表达量,而y轴是细胞系中该表达的频率.但是,我想将细胞系的名称添加到直方图上的特定位置...该怎么做?

and it gives me the histogram whose x axis is the amount of gene expression and the y axis is the frequency of that expression among cell lines; however, I would like to add the name of cell lines to their specific positions on histogram... How can I do that?

在此先感谢您的时间:-) 最好.

Thanks in advance for your time on answering this :-) Best.

推荐答案

一种替代方法是使用text在图中插入标签:

One alternative is to use text to insert labels into the plot:

hist(Heiser$ZEB1[1:19], breaks=50, col="grey")
text(Heiser$ZEB1, 2, labels= Heiser$CellLines, srt=90)

将同一类别中的标签彼此定位:

Positioning labels in the same category one over another:

Heiser_hist <- hist(Heiser$ZEB1[1:19], breaks=50, col="grey")
Heiser$cut <- cut(Heiser$ZEB1, breaks=Heiser_hist$breaks)
library(dplyr)
Heiser <- Heiser %>% group_by(cut) %>% mutate(pos = seq(from=1, to=2, length.out=length(ZEB1)))
with(Heiser, text(ZEB1, pos, labels=CellLines, srt=45, cex=0.9))

您可以在不更改srt的情况下尝试使用文本,但是在这种情况下,过度绘图会更糟.您也可以使用x轴来减少过度绘制.

You could try the text without inclination changing srt, but the overplotting is worse in that case. You could also play with the x axis to reduce overplottig.

这篇关于通过为R中每个条形图的不同段分配名称来使直方图更清晰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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