【问题标题】:Adding partial horizontal lines with ggplot2 in R在 R 中使用 ggplot2 添加部分水平线
【发布时间】:2015-06-12 21:42:56
【问题描述】:

我有以下数据:

mydf = read.table(text="
name a b
x 10 15
y 20 25
z 35 45
", header = T)

我想创建一个情节如下:

我无法将水平线从点添加到 x=50 处的垂直线。这些线(蓝色)已在上图中手动绘制。我尝试了以下代码,但它不起作用:

ggplot(mydf, aes(a, b)) + geom_point()+ 
     geom_vline(xintercept=50)+ 
     geom_line(aes(x=50,y=b, group=name))

【问题讨论】:

  • 你看了吗geom_segment

标签: r ggplot2


【解决方案1】:

试试geom_segment

ggplot(mydf, aes(a, b)) +
  geom_point()+ 
  geom_vline(xintercept=50) + 
  geom_segment(aes(x=a, xend=50, y=b, yend=b), colour="blue")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多