ggplot2 - Conserve grouping in ggrepel (R) -


i label points "box points"-plot sub-grouped. problem current ggrepel code omits sub-grouping.

here example df:

phenotype <- c("healthy", "healthy","healthy", "sick1", "sick1","sick1",  "sick2", "sick2", "sick2" ) individual <-c(1:9) genotype <- c("nothing", "nothing", "nothing", "muta", "unknown", "muta", "mutb", "unknown", "unknown") variable <- c("var1", "var1", "var1", "var1", "var1", "var1", "var1", "var1", "var1") value <- c("1.2", "1.3", "1.3", "2.5", "2.5", "2.4", "4.1", "4.2", "4.3") df <- data.frame(phenotype, individual, genotype, variable, value) 

and here code plot:

library(ggplot2) library(ggrepel)      ggplot (data= subset(df, variable == "var1"), aes(x = phenotype, y=value, fill=genotype)) + geom_boxplot() + geom_dotplot(binaxis='y', stackdir='center', position=position_dodge(0.75), dotsize=0.5) + scale_fill_discrete(breaks=c("muta","mutb","nothing")) + labs(title= "expression of var1 according genotype", x= "phenotype", y="expression value")+ theme(axis.text=element_text(size=20), axis.title=element_text(size=24), plot.title = element_text(size=26, face="bold"), legend.text = element_text(size=20), legend.title = element_text(size=24)) + guides(fill=guide_legend(title="genotype")) + geom_text_repel (data = subset(df, genotype == "unknown" & variable == "var1"), aes(label = individual)) 

the df not contain enough data points box plot (as noticed) still serves fine illustrate problem label "individual 9" misplaced.

thanks lot , sorry beginners mistakes made in question - im still learning ;) sebastian

enter image description here


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -