【问题标题】:How to make this plot in ggplot如何在ggplot中制作这个情节
【发布时间】:2019-10-25 01:02:45
【问题描述】:

我想创建一个这样的人物。我不知道它是什么类型的图形,并且在 ggplot 中找不到参考。我应该使用什么“关键字”来搜索互联网?

【问题讨论】:

  • 看起来像虚线的geom_path(),或带有coord_flip() 的geom_line()。对于较粗的条,您可能可以使用geom_rect()/geom_tile()。我不知道有任何明确适用于这类图的几何函数。

标签: r ggplot2 figure step


【解决方案1】:

这可以通过单个geom_segment() 来完成。设置一列来定义线段是垂直还是对角线。使用比例将该列分别映射到(实线、粗体、紫色)和(虚线、细线、黑色)。

library( tidyverse )

# Data
X <- tibble(
  x = rep(c(100, 150, 800, 750, 850, 1250, 4300, 2300, 3300, 6100), each=2),
  y = c(0,2, 4,8, 10,15, 20,45, 50,70, 80,100, 110,130, 140,160, 230,245, 280,310),
  x1 = c(x[-1],0), y1 = c(y[-1],310), type=ifelse(x==x1,"vert","diag") )
# # A tibble: 20 x 5
#        x     y    x1    y1 type 
#    <dbl> <dbl> <dbl> <dbl> <chr>
#  1   100     0   100     2 vert 
#  2   100     2   150     4 diag 
#  3   150     4   150     8 vert 
#  4   150     8   800    10 diag 
# ...

ggplot(X) + theme_bw() + scale_y_reverse() +
    geom_segment( aes(x=x, y=y, xend=x1, yend=y1,
                      linetype=type, size=type, color=type) ) +
    scale_linetype_manual( values=c(diag="dashed", vert="solid") ) +
    scale_size_manual( values=c(diag=0.5, vert=2) ) +
    scale_color_manual( values=c(diag="black", vert="darkorchid4") ) +
    guides( linetype=FALSE, size=FALSE, color=FALSE ) +
    xlab( "Concentration" ) + ylab( "Depth (cm)" )

【讨论】:

  • 谢谢你,阿尔乔姆。正是我要找的!
猜你喜欢
  • 1970-01-01
  • 2021-10-24
  • 2017-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
相关资源
最近更新 更多