r - Change dots of a ggplot to text labels -


recently asked question getting multiple graphs within 1 picture. got pretty answers 1 question still remains.

how change dots scatter plot labels? plot looks enter image description here

now want black dots changed rownames of data. code use plotting follows:

plotall<-function(data){   combs <- expand.grid(names(data), names(data))   out <- do.call(rbind, apply(combs, 1, function(x) {     tt <- data[, x]; names(tt) <- c("v1", "v2")     tt <- cbind(tt, id1 = x[1], id2 = x[2])   }))    library(plyr)   df.text=ddply(out[out$id1==out$id2,],.(id1,id2),summarise,                 pos=max(v1)-(max(v1)-min(v1))/2)   out[out$id1==out$id2,c("v1","v2")]<-na   ggplot(data = out, aes(x = v2, y = v1)) + geom_point(alpha = 0.5) +     facet_grid(id1 ~ id2,scales="fixed")+     geom_text(data=df.text,aes(pos,pos,label=id1)) + geom_abline( slope=1 ) +      ggtitle("corralation between measured & calculated affinities") +     ylab("") + xlab("") + theme(panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank()) } 

i know have change settings of geom_point(alpha=0.5) geom_text(label=rownames(data)) deletes axes , places rownames onto y-axes , datapoints. did wrong lay out of plot remains question.

so turned out more difficult thought... basic problem na values - geom_text can't handle them. that's pretty easy fix doing:

geom_text(data = out[!is.na(out$v1),], label = "test") 

but when go rownames label gets problematic. didn't figure out why, got around adding label column dataframe. full function below.

plotall<-function(data){   combs <- expand.grid(names(data), names(data))   out <- do.call(rbind, apply(combs, 1, function(x) {     tt <- data[, x]; names(tt) <- c("v1", "v2")     tt <- cbind(tt, id1 = x[1], id2 = x[2])   }))    library(plyr)   df.text=ddply(out[out$id1==out$id2,],.(id1,id2),summarise,                 pos=max(v1)-(max(v1)-min(v1))/2)   out[out$id1==out$id2,c("v1","v2")]<-na   out$labels <- rownames(out)   ggplot(data = out, aes(x = v2, y = v1)) + geom_text(data = out[!is.na(out$v1),], aes(label = labels)) +     facet_grid(id1 ~ id2,scales="fixed")+     geom_text(data=df.text,aes(pos,pos,label=id1)) + geom_abline( slope=1 ) +      ggtitle("corralation between measured & calculated affinities") +     ylab("") + xlab("") + theme(panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank()) } plotall(data) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -