简体   繁体   中英

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. Any input on the "keywords" I should use to search the internet?

核心简介

This can be done with a single 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.

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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