有沒有辦法改變R中缺失數據點的形狀?我正在繪製一個棒棒糖樣式的.csv文件。如何使用ggplot2說明不同形狀的非可用數據點?
Name,chr,Pos,Reads...ME_016,Reads...ME_017,Reads...ME_018,Reads...ME_019
cg01389728,chr10,6620395,33.82,41.38,41.38,38.46
cg01389728,chr10,6620410,0,-,-,-
cg01389728,chr10,6620430,0,0,-,-
cg01389728,chr10,6620447,0,-,0,-
cg01389728,chr10,6620478,0,-,-,-
cg01389728,chr10,6620510,28.33,29.85,25.64,28.13
cg01389728,chr10,6620520,0,0,-,0
cg01389728,chr10,6620531,0,-,50,-
使用GGPLOT2,我的圖表與此創建:
dataset <-read.table("testset", sep=",",na.strings="-", header=TRUE)
dataset <- subset(dataset, select=c(-Name, -chr))
dataset <- melt(dataset, id.vars="Pos")
dataset$variable <- gsub("\\.\\.\\.","_",dataset$variable)
xaxes <- unique(dataset$Pos)
dataset$Pos <- as.factor(dataset$Pos)
ggplot(dataset, aes(x=Pos, y=variable,fill=cut(value, breaks=10))) + geom_point(size=4, shape=21) + geom_line() + scale_fill_discrete(labels=c("0-10%","10-20%","20-30%","30-40%","40-50%","50-60%","60-70%","70-80%","80-90%","90-100%")) +
xlab("CpG Positions") +
ylab("Sample") +
labs(fill="Coverage in %") +
theme_bw() +
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5),plot.title = element_text(vjust=2),axis.title.x = element_text(vjust=-0.5),axis.title.y = element_text(vjust=1.5))
不過,我想缺少點的形狀(「 - 」)設置的情節一個「x」, (shape = 4)並在圖例中顯示它們。 我已經試過方法,如:
scale_fill_manual(values=c(value, NA))
或:
scale_shape_manual(values=c(21,4))
默認情況下, 「 - 」 也顯示與形狀21和灰色。必須有辦法來操縱這個?編寫這樣的方法可能是個訣竅,但是如何將其稱爲整列?
formas <- function(x){
+ if(is.na(x)) forma <- 4
+ if(!is.na(x)) forma <- 21
+ return(forma)
+ }
適合我。偉大的想法就是用顏色「覆蓋」形狀! – user3401516 2014-11-26 14:21:08