Dav*_*ack 5 pdf r ggplot2 r-factor
我有一个项目,我正在生成一个多页的pdf.每个页面都有一个基于使用plyr的数据帧子集的单独图.我正在使用一个因子来控制每个图中点的颜色,但我似乎无法使颜色保持一致.
下面的示例生成一个两页的pdf文件,该文件复制了我正在经历的内容.您会注意到,当过滤的图形#2不包含红色条目时.当图形生成时,我尝试以蓝色显示的点实际上显示为红色.
require(plyr)
require(ggplot2)
graphNumber <- c(1,1,1,1,1,1,2,2,2,2,2,2)
x <- c(1,2,3,4,5,6,1,2,3,4,5,6)
y <- c(1,2,3,4,5,6,1,2,3,4,5,6)
theColor <- c("red","red","red","blue","blue","blue","blue","blue","blue","blue","blue","blue")
temp <- data.frame(graphNumber, x, y, theColor)
temp$theColor = factor(temp$theColor, levels=c("red","blue"))
str(temp)
plotpattern <- function(dfIn) {
qplot(x, y, data=dfIn, color=theColor, geom = "point")
}
pdf("test.pdf", width = 6, height = 4)
d_ply(temp, .(graphNumber), failwith(NA, plotpattern), .print = TRUE)
dev.off()
Run Code Online (Sandbox Code Playgroud)
有关我可能需要改变什么的想法让ggplot在分配颜色时始终认可我的所有因素?即使过滤后数据中没有出现特定因素?
| 归档时间: |
|
| 查看次数: |
142 次 |
| 最近记录: |