【问题标题】:lattice in R- line typesR 线类型中的晶格
【发布时间】:2017-04-24 23:55:30
【问题描述】:

我有一个带有平滑线的格子 xyplot(6 条不同的线)。我想更改线条类型 - 颜色和线条类型(虚线等),以便它们在黑白中可以理解,而不是在颜色中(这是默认设置)。任何人都可以就此提供建议吗?以下是我当前的代码:

xyplot(y~x,
 data=df,
 group=categorical,
 type = "smooth",
 ylim=c(-2,0.5),
 xlab="x",
 ylab="y",
 auto.key=list(space="top",
 columns=3,
 title="",
 cex.title=0.1,
 lines=FALSE, points=TRUE)
)

谢谢

【问题讨论】:

标签: r lattice


【解决方案1】:

有两种选择。要么使用lty = 1:x 设置线条类型,要么使用内置的黑白主题——后者也会设置许多其他设置。

library(lattice)

y <- c(rnorm(10), rnorm(10, 2, 0.2), rnorm(10, 1.5, 0.4))
x <- rep(1:10, times = 3)
z <- rep(letters[1:3], each = 10)


# Option 1
xyplot(y ~ x, groups = z, type = "l",
       par.settings = standard.theme(color = FALSE))


# Option 2
xyplot(y ~ x, groups = z, type = "l", lty = 1:3, col = "black")

【讨论】:

  • 非常感谢,选项 1 对我来说效果很好。
  • 我很高兴它为您工作@Autumn - 如果您认为它解决了您的问题,请考虑接受答案。
猜你喜欢
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 2013-12-30
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
相关资源
最近更新 更多