【发布时间】: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() 函数中的 limits 和 mapping 参数,但没有成功。
我怎样才能让这张图片打印数字代码和他们的名字?
【问题讨论】: