R 画一幅图

R 画一幅图,r,plot,R,Plot,我有一个这样的框架 ____y:1 2 4 x_min:1 2 1 x_最大值:15 如何绘制这样的图形?使用ggplot: require(ggplot2) #data prep df <- read.table(text="____y : 1 2 4 x_min : 1 2 1 x_max : 1 5 5",as.is=TRUE) df1 <- as.data.frame(t(df[,3:5])) colnames(df1) <- c("y","x_min","x

我有一个这样的框架

  • ____y:1 2 4
  • x_min:1 2 1
  • x_最大值:15


如何绘制这样的图形?

使用
ggplot

require(ggplot2)

#data prep
df <- read.table(text="____y : 1 2 4
x_min : 1 2 1
x_max : 1 5 5",as.is=TRUE)

df1 <- as.data.frame(t(df[,3:5]))
colnames(df1) <- c("y","x_min","x_max")

df1
#    y x_min x_max
# V3 1     1     1
# V4 2     2     5
# V5 4     1     5

#plot
ggplot(df1,aes(x = x_min, y = y, xend = x_max, yend = y)) +
  geom_segment() +
  #added point, to show zero length lines.
  geom_point()
require(ggplot2)
#数据准备

谢谢!我想给你的答案加上+1,但我没有足够的声誉=(