【问题标题】:How to solve Error in grid.Call.graphics(C_segments, x$x0, x$y0, x$x1, x$y1, x$arrow)如何解决 grid.Call.graphics 中的错误(C_segments,x$x0,x$y0,x$x1,x$y1,x$arrow)
【发布时间】:2019-12-05 08:56:14
【问题描述】:

我通过修改位于ggpubr 包中的一个函数来创建这个函数,称为show_line_types()。我希望这个函数有线型的数字代码:

lineas_r <- function () 
{
    lt <- c("1 blank", "2 solid", "3 dashed", "4 dotted", "5 dotdash", 
        "6 longdash", "7 twodash")
    d <- data.frame(lt = factor(lt, levels = lt))
    ggplot() + scale_x_continuous(name = "", limits = c(0, 1), 
        breaks = NULL) + scale_linetype_identity() + geom_segment(data = d, 
        mapping = aes(x = 0, xend = 1, y = lt, yend = lt, linetype = lt)) + 
        labs(y = "") + theme(axis.text.y = element_text(face = "bold", 
        color = "black"))
}

一旦运行,我得到这个错误:

Error in grid.Call.graphics(C_segments, x$x0, x$y0, x$x1, x$y1, x$arrow) : invalid line type: must be length 2, 4, 6 or 8

但是,当我对对象lt做同样的修改时,如下所示:

lt <- c("blank", "solid", "dashed", "dotted", "dotdash", 
        "longdash", "twodash")

我没有收到此错误。

我尝试修改 ggplot() 函数中的 limitsmapping 参数,但没有成功。

我怎样才能让这张图片打印数字代码和他们的名字?

【问题讨论】:

    标签: r function ggplot2 ggpubr


    【解决方案1】:

    问题是您将线型映射到不包含预期线型的矢量。这是一种可能的解决方案:

    lt <- c("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash")
    lt_names <- c("1 blank", "2 solid", "3 dashed", "4 dotted", "5 dotdash", "6 longdash", "7 twodash")
    
    d <- data.frame(lt, lt_names)
    
    ggplot() + scale_x_continuous(name = "", limits = c(0, 1), breaks = NULL) + 
      scale_linetype_identity() + 
      geom_segment(data = d, mapping = aes(x = 0, xend = 1, y = lt_names, yend = lt_names, linetype = lt)) + 
      labs(y = "") + 
      theme(axis.text.y = element_text(face = "bold", color = "black"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-19
      • 2020-04-24
      • 2015-07-14
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多