我的数据如下:
grp = rep(1:2, each = 100)
chr = c(rep(1:10, each = 10), rep(1:10, each = 10))
var = paste (grp, "chr", chr, sep = "")
pos = (rep(1:10, 20))
yvar = rnorm(200)
mydf = data.frame (var, pos, yvar)
require( lattice)
xyplot(yvar ~ pos| factor(var), data = mydf, layout = c(1,10), type = c("g", "h"),
col = "darkolivegreen", lwd = 4)
Run Code Online (Sandbox Code Playgroud)
(1)我想把不同的颜色用于交替的图形/面板 - 例如 - 2chr1是暗绿色但是chr10说是紫色.然后又是深橄榄绿和紫色等等.
(2)我想使用2chr9位于底部的图表的逆序.
谢谢

我一直在研究R中一个相当复杂的图表.我有一个带有表面的线框,点分布在X,Y,Z空间中(例如在表面下面和上面).
问题在于情节不会"看起来"像点在表面之下.
我试图弄清楚如何最好地可视化此图表,使点看起来在表面下.线框和云的一些示例代码来自此处: R-List Posting
示例中的代码:
library(lattice)
surf <-
expand.grid(x = seq(-pi, pi, length = 50),
y = seq(-pi, pi, length = 50))
surf$z <-
with(surf, {
d <- 3 * sqrt(x^2 + y^2)
exp(-0.02 * d^2) * sin(d)
})
g <- surf
pts <- data.frame(x =rbind(2,2,2), y=rbind(-2,-2,-2), z=rbind(.5,0,-.5))
wireframe(z ~ x * y, g, aspect = c(1, .5),
drape=TRUE,
scales = list(arrows = FALSE),
pts = pts,
panel.3d.wireframe =
function(x, y, z,
xlim, ylim, zlim,
xlim.scaled, ylim.scaled, zlim.scaled,
pts, …Run Code Online (Sandbox Code Playgroud) 我正在dotplot()使用lattice或Dotplot()使用Hmisc.当我使用默认参数时,我可以绘制没有小垂直结束的误差条
--O -
但我想得到
| --O - |
我知道我能得到
| --O - |
当我使用centipede.plot()从plotrix或segplot()从latticeExtra,但这些解决方案并没有给我这么好的调理选项Dotplot().我试图用玩par.settings的plot.line,这对于改变错误条线的颜色,宽度等效果很好,但到目前为止,我一直在增加垂直的结局是不成功的:
require(Hmisc)
mean = c(1:5)
lo = mean-0.2
up = mean+0.2
d = data.frame (name = c("a","b","c","d","e"), mean, lo, up)
Dotplot(name ~ Cbind(mean,lo,up),data=d,ylab="",xlab="",col=1,cex=1,
par.settings = list(plot.line=list(col=1),
layout.heights=list(bottom.padding=20,top.padding=20)))
Run Code Online (Sandbox Code Playgroud)

请不要给我使用ggplot2的解决方案......
当绘制比完整网格更少的面板时,您将获得没有面板的间隙.大多数格子函数都将间隙放在右上角,但我想将它放在右下角,如图所示marginal.plot(见图).有没有办法让其他格子函数做同样的事情?

我知道面板顺序是由条件变量的因子级别的顺序决定的,或者通过使用index.cond参数来决定,但这对我没有帮助.我试图破译代码marginal.plot,但一直无法弄清楚,所以任何帮助表示赞赏!
为了在匹配过程之前和之后直观地显示协变量平衡,我编写了以下代码:
library(lattice)
library(gridExtra)
StandBias.df= data.frame(
Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
Groups = factor(c(rep("0", 6), rep("1", 6))),
Values = c(0.26, 0.4, 0.3, 0.21, 0.6, 0.14, 0.12, -0.04, -0.23, 0.08, 0.14, -0.27))
d1<-dotplot(Category ~Values, data = StandBias.df, groups = Groups,
main = "Standardized Mean Differences", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
key=list(text=list(c("Pre-Matching", "Post-Matching")),
points=list(col = c("black", "grey50"), pch=c(22,15)),
space="bottom", border=T))
Ttest.df = data.frame(
Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
Groups = factor(c(rep("0", 6), rep("1", 6))),
Values = …Run Code Online (Sandbox Code Playgroud) 我有一个all看起来像这样的数据框:
现在我想创建一个散点图,其中x轴的列标题和相应的值作为数据点.例如:
7| x
6| x x
5| x x x x
4| x x x
3| x x
2| x x
1|
---------------------------------------
STM STM STM PIC PIC PIC
cold normal hot cold normal hot
Run Code Online (Sandbox Code Playgroud)
这应该很容易,但我无法弄清楚如何.
问候
我使用晶格包parallelplot方法绘制数据并遇到生成图例的麻烦.我为绘图创建了一个自定义颜色矢量,但找不到传递它们的方法来覆盖图例中显示的默认颜色.虽然我已经没时间了,最终在Photoshop中修正了图例颜色,但我想学习在格子中执行此操作的正确方法.
以下是使用4列图例生成绘图的代码:
parallelplot(acc, horizontal.axis=FALSE, col=acc_colors, lwd=1.5, cex=2.5,
ylab="Accuracy (Min = 50%, Max = 100%)",
xlab="Activity (overall = average across activities)",
main="Human Activity Recognition Accuracy",
scales=list(cex=1),
auto.key=list(text=c("Test Set", "Test Subject", "Training Set", "Training Subject"),
title=" ",
space="top", columns=4, points=FALSE)
)
Run Code Online (Sandbox Code Playgroud)
有关如何传递自定义图例颜色的任何想法?
这次讨论的后续stackexchange我试图执行下列情节
从
Cumming,G.,&Finch,S.(2005).[眼睛推理:置信区间和如何读取数据图片] [5].美国心理学家,60(2),170-180.DOI:10.1037/0003-066X.60.2.170
我有些人不喜欢双轴,但我认为这是一个合理的用途.
在我的部分尝试之下,第二个轴仍然缺失.我正在寻找更优雅的替代品,欢迎智能变化.
library(lattice)
library(latticeExtra)
d = data.frame(what=c("A","B","Difference"),
mean=c(75,105,30),
lower=c(50,80,-3),
upper = c(100,130,63))
# Convert Differences to left scale
d1 = d
d1[d1$what=="Difference",-1] = d1[d1$what=="Difference",-1]+d1[d1=="A","mean"]
segplot(what~lower+upper,centers=mean,data=d1,horizontal=FALSE,draw.bands=FALSE,
lwd=3,cex=3,ylim=c(0,NA),pch=c(16,16,17),
panel = function (x,y,z,...){
centers = list(...)$centers
panel.segplot(x,y,z,...)
panel.abline(h=centers[1:2],lty=3)
} )
## How to add the right scale, close to the last bar?
Run Code Online (Sandbox Code Playgroud)

xyplot从lattice包中使用,我绘制了多年的时间序列.我想在这些年中添加一个阴影区域,以表明这段时间是"特殊的"(例如战争).
请道歉,如果这是微不足道的,但我无法弄清楚如何做到这一点,所以如果有人可以帮助我,或者至少指出我正确的方向,我会很高兴.我认为我的主要问题是我真的不知道如何处理这个问题.我对R来说还是比较新的lattice,特别是.
这是一个最小的例子:
xyplot( rnorm(100) ~ 1:100, type="l", col="black")
Run Code Online (Sandbox Code Playgroud)
在相应的图中,我想要从x绘图区域的底部到顶部的背景颜色(从45到65的值),例如浅灰色.
请注意,到目前为止我找到的解决方案使用base图形和polygon函数,但目的是遮蔽曲线下方或上方的区域,这与我想要做的不同.我不是"只是"想要遮挡我的线下方或我线以上的区域.相反,我想在给定的时间间隔内遮蔽整个背景.
如果有人能帮助我,我会非常感激!
有没有人知道如何更改levelplot图形的线宽,特别是多个面板的线宽?箱线宽度应与刻度线一起变化.在基地R可以使用plot(x);box(lwd=10).
这是否可以在levelplot中?
非常感谢.
library(rasterVis)
mycolors=c("darkred","red3", "orange", "yellow", "lightskyblue",
"royalblue3","darkblue")
s <- stack(replicate(6, raster(matrix(runif(100), 10))))
levelplot(s, layout=c(3, 2), col.regions=mycolors, index.cond=list(c(1, 3, 5, 2, 4, 6)))
Run Code Online (Sandbox Code Playgroud)