水平线图与assambly在R [英] horizontal line graph with assambly in R

查看:157
本文介绍了水平线图与assambly在R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  pos <-c(1,3, (1,3,6,7,10,11)
end <-c(5,6,9,10,13)
start <-c(1,3,6,7,10,11)
end < 12)

Qunatative变量Pos为Y轴,X轴为anthor X变量(定量)。每个Pos值的水平条长度由开始点和结束点定义。例如,line for 1将从1开始,并在x轴3结束。 下面是所需图形输出的粗略草图。



解决方案使用包 ggplot2 geom_segment 绘制线。



首先将数据合并到 data.frame 中,因为这是所需的数据 ggplot

  dat < -  data.frame(
pos = c(1,3,5,8,10,12),
start = c(1,3,6,7,10,11),
end = c(5 ,6,9,9,13,12)

创建图:

  library(ggplot2)
ggplot(dat)+
geom_segment(aes(x = start,y = pos,xend = end,yend = pos),color =blue,size = 3)+
scale_y_reverse()


I have big data like the following but this just little sample.

pos <- c(1, 3, 5, 8, 10, 12)
start <- c(1,3, 6, 7, 10, 11)
end <- c(5, 6, 9, 9, 13, 12)

Qunatative variable Pos will be Y axis and X axis will be anthor X variable (quantitative). The horizontal bar length for each Pos value is defined by start and end point. For example,line for 1 will start from 1 and end at 3 in x axis.

The following is rough sketch of desired the figure output.

解决方案

Use package ggplot2 with geom_segment to draw the lines.

Start by combining your data into a data.frame, since this the required data structure for ggplot:

dat <- data.frame(
  pos = c(1, 3, 5, 8, 10, 12),
  start = c(1,3, 6, 7, 10, 11),
  end = c(5, 6, 9, 9, 13, 12)
)

Create the plot:

library(ggplot2)
ggplot(dat) + 
    geom_segment(aes(x=start, y=pos, xend=end, yend=pos), color="blue", size=3) +
    scale_y_reverse()

这篇关于水平线图与assambly在R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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