r - 如何重复 ggplot 图例中的符号以获得更好的符号 View ?

标签 r ggplot2 legend symbols

我刚刚开始杜波依斯挑战,作为 #tidytuesday 的一部分,目前正在挑战挑战 1:乔治亚州白人和有色人种人口的相对增长

原始图表具有带有 4 个破折号的“白色”符号 enter image description here ,但是当我复制该图时,图例只有 1 和第二个破折号的一点。

如何重复图例中的符号以获得 4 个破折号?我不需要增加大小,只需重复

最佳答案

尝试在主题中设置legend.key.width:

library(ggplot2)

ggplot(df1, aes(x, y, linetype = f)) +
  geom_line() +
  scale_linetype_manual(values = c("solid", "dashed")) +
  theme(legend.key.width = unit(1.5, "strwidth", "- - - - "))

enter image description here

测试数据

set.seed(2021)
df1 <- data.frame(
 x = c(1:10, 1:10),
 y = c(cumsum(rnorm(10)), cumsum(rnorm(10))),
 f = rep(c("A", "B"), each = 10)
)

关于r - 如何重复 ggplot 图例中的符号以获得更好的符号 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66231244/

相关文章:

r - ggplot 按因子和梯度颜色

linux - JRI REngine eval() 方法总是返回 null

R:使用 Alpha 控制填充

r - 为什么从函数内部调用cv.tree()找不到此对象?

r - 使用facet_wrap时在ggplot2中使用具有不同比例因子的辅助y轴

flot - 图例条目和堆积条的顺序相反

jquery - 在具有自动滚动功能的 div 中添加 d3 图例

python - 无法在 seaborn distplot 中显示图例

r,dplyr : how to transform values in one column based on value in another column using gsub

python - 替换部分 fasta header