简体   繁体   English

如何在ggplot中制作这个plot

[英]How to make this plot in ggplot

I want to create a figure like this.我想创建一个这样的人物。 I do not know what type of figure it is, and cannot find a reference in ggplot.我不知道它是什么类型的图形,并且在 ggplot 中找不到参考。 Any input on the "keywords" I should use to search the internet?我应该使用什么“关键字”来搜索互联网?

核心简介

This can be done with a single geom_segment() .这可以通过一个geom_segment()来完成。 Set up a column that defines whether a segment is vertical or diagonal.设置一列来定义线段是垂直还是对角线。 Use scales to map that column to (solid, bold, purple) and (dashed, thin, black) respectively.使用比例尺 map 该列分别为(实心,粗体,紫色)和(虚线,细,黑色)。

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)" )

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM