ggplot2错误:美学必须是长度为1或与dataProblems相同的长度:颜色,字母

时间:2015-07-22 06:48:11

标签: r ggplot2

我收到了这个错误:

  

错误:美学必须是长度为1或与dataProblems相同的长度:颜色,字母

当我使用带有数据帧RewriteEngine On RewriteRule ^(partnerships/mt4-to-mt4-bridge|platforms/mt4-ecn)/?$ / [L,NC,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ public/index.php [L] 的ggplot时,如下所示:

Z

在这里,我创建了一个颜色调色板,以便稍后应用于Z <- data.frame("Name"=c("A","G","C","T","T","T","AG","AG","GC","GC","CT","CT","AT","AT","CT","CT"), "Track"=c(0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1), "Position"=c(1,1,1,1,1,1,1,2,2,3,3,4,9,10,12,13)) Z[1:16] # Small dummy sample # Name Track Position # 1 A 0 1 # 2 G 0 1 # 3 C 0 1 # 4 T 0 1 # 5 T 0 1 # 6 T 0 1 # 7 AG 1 1 # 8 AG 1 2 # 9 GC 1 2 # 10 GC 1 3 # 11 CT 1 3 # 12 CT 1 4 # 13 AT 1 9 # 14 AT 1 10 # 15 CT 1 12 # 16 CT 1 13

geom_raster

此代码试图绘制所有内容:

# Create color palette
x <- length(levels(Z$Name))               
x.colors <- hcl(h=seq(15,375,length=(x+1)),l=65,c=100)[1:x]
x.colors[1:4] <- c("blue","red","green","yellow")    
colors <- factor(x.colors)
letters <- factor(levels(Z$Name))
my_fill <- x.colors

1 个答案:

答案 0 :(得分:1)

(为了清晰起见,添加一个完整的答案;巩固Pascal,johnson_shuffle和Jaap的评论)

绘图代码应如下所示:

ggplot(Z, aes(x=Track, y=Position, fill=Name, label=Name)) +
  geom_raster() +
  geom_text()