这是我的示例数据:
> head(Plot,n=10)
start end variable value
1 0 499999 control 1
2 500000 999999 control 1
3 1000000 1499999 control 1
4 1500000 1999999 control 1
5 2000000 2499999 control 1
6 2500000 2999999 control 1
7 3000000 3499999 control 1
8 3500000 3999999 control 1
9 4000000 4499999 control 2
10 4500000 4999999 control 2
我想绘制矩形(这有效)但是我无法匹配填充和放大轮廓颜色。
我尝试了什么:
MyPlot <- ggplot(Plot, aes(xmin=start, xmax=end, ymin=0, ymax=1, fill=factor(value))) +
geom_rect(linetype=1, size=0.3, color=factor(value))
Error in factor(value) : object 'value' not found
# This should work somehow as I am getting wanted output if using this:
# geom_rect(linetype=1, size=0.3, color="black")
我尝试将color
放入aes
,但是fill
并且轮廓颜色不匹配:
MyPlot <- ggplot(Plot, aes(xmin=start, xmax=end, ymin=0, ymax=1, fill=factor(value),color=factor(value))) +
geom_rect(linetype=1, size=0.3)
我用以下内容绘制所有内容:
# I have to use pdf
pdf(paste(Variable,".pdf",sep=""),
width = par("din")[1] * 2,
height = par("din")[2] * 1)
print(MyPlot + scale_fill_manual(values=MyPallete))
dev.off()
我的问题:
color=factor(value)
&amp;不要弄错?fill
和大纲之间的颜色?答案 0 :(得分:1)
我用scale_colour_manual
解决了我的问题。当我手动缩放填充时,我还必须手动缩放colour
。
MyPlot <- ggplot(Plot, aes(xmin=start, xmax=end, ymin=0, ymax=1, fill=factor(value),color=factor(value))) +
geom_rect(linetype=1, size=0.3)
# I have to use pdf
pdf(paste(Variable,".pdf",sep=""),
width = par("din")[1] * 2,
height = par("din")[2] * 1)
print(MyPlot + scale_fill_manual(values=MyPallete) +
scale_colour_manual(values=MyPallete))
dev.off()