【发布时间】:2019-03-23 22:14:19
【问题描述】:
我在 ggplot 中看到了几篇关于 changing line width 的帖子。答案虽然对 OP 来说信息丰富且有效,但改变了 size 行。也就是说,ggplot 似乎将线条视为一系列单位,而 size 增加了每个单位的长度和宽度,使其他调整更粗略。
我希望有一种方法可以使线条更宽(更粗),而不会影响长度,进而影响破折号的比例。
我从https://cran.r-project.org/web/packages/ggplot2/vignettes/ggplot2-specs.html借了一些代码来说明我的意思:
library(ggplot2)
#A simple plot with manually set dashes.
#The first numeral is units of dash length, the second units in the gap in hexadecimal.
lty <- c("11", "18", "1f", "81", "88", "8f", "f1", "f8", "ff")
linetypes <- data.frame(y = seq_along(lty), lty = lty)
ggplot(linetypes, aes(0, y)) +
geom_segment(aes(xend = 5, yend = y, linetype = lty)) +
scale_linetype_identity() +
geom_text(aes(label = lty), hjust = 0, nudge_y = 0.2) +
scale_x_continuous(NULL, breaks = NULL) +
scale_y_reverse(NULL, breaks = NULL)
#Altering the size changes the line width AND dash spacing.
ggplot(linetypes, aes(0, y)) +
geom_segment(aes(xend = 5, yend = y, linetype = lty),
size = 3) +
scale_linetype_identity() +
geom_text(aes(label = lty), hjust = 0, nudge_y = 0.3) +
scale_x_continuous(NULL, breaks = NULL) +
scale_y_reverse(NULL, breaks = NULL)
基本上我想要的是粗线,相对较细和精细调整的间隙。我认为这是以另一种方式提出的同一个问题:有没有办法让所有的线条,比如说,“虚线”在宽度上有所不同,但在破折号的相对位置上没有?像这样(我完全伪造):
【问题讨论】:
-
我只想提一下,这里发布了一个类似的问题:stackoverflow.com/questions/63061601/…。有些答案可能也能解决您的问题。