【发布时间】:2021-10-16 08:13:47
【问题描述】:
我正在尝试使用长度小于 1 的虚线网格线设置主题,但鉴于单位为十六进制,我不确定这是否可行。现在我将线型设置为“11”,而我真的希望它类似于 c("0.5", "1")。
这是我在尝试中引用的 ggplot2 材料:
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)
此处引用:https://cran.r-project.org/web/packages/ggplot2/vignettes/ggplot2-specs.html
【问题讨论】:
-
“当我真的希望它类似于
c("0.5", "1")”是什么意思? -
linetype="11"的含义如下。第一个表示点的长度为 1,第二个表示点的间隙为 1。我想要的是 0.5 的长度和 1 的间隙。
-
换句话说,您希望破折号的段比宽度高吗?对吗?
-
@JonSpring 我主要是想让点比“1”更窄。不关心点本身的高度与宽度。