Plotting

Data visualization

ggplot simple plot commands

# adding title to ggplot-object
gg + ggtitle("My title")

#customize labels of axes
gg +xlab("Dose (mg)") 
gg + ylab("Teeth length")


# divide legend in two columns
gg + guides(fill=guide_legend(ncol=2))

Correlation matrix

z <- cor(myData,use="pairwise.complete.obs")
xTable = xtable(z)

pdf('CON.pdf')
ggplot(z.m, aes(X1, X2, fill = value)) 
+ geom_tile() 
+ scale_fill_gradient(low = "white",  high = "black")
dev.off()

Boxplot with error bars

dist=ggplot(distdataSum, aes(x=Region, y=Value, colour=Diagnosis, group=Diagnosis)) +
    scale_colour_manual(values=c("#CC0000","#FF9900","#0000CC"),name="Diagnostic group")+ 
    geom_errorbar(aes(ymin=Value-se, ymax=Value+se, group=Diagnosis), colour="black", width=.1) +
    geom_line(size=0.7) +
    geom_point() +
    ylab("Parameter Estimate") +
    theme_bw() 
print(dist)
dev.off()


Plot with facets

distdataSum <- summarySE(mdata2, measurevar="Value", groupvars=c("Region","Diagnosis"),na.rm=T)
distdataSum$Phase="Anticipation"
distdataSum$Phase[1:6]="ROI Analysis"
distdataSum$Phase[16:27]="Receipt"
distdataSum$Phase=factor(distdataSum$Phase, levels=c("Anticipation","Receipt","ROI Analysis"))
distdataSum$FieldName=c(1,1,1,2,2,2,1,1,1,2,2,2,3,3,3,1,1,1,2,2,2,3,3,3,4,4,4)

pdf(paste('Brainendophenotypes.pdf',sep=''))
dist=ggplot(distdataSum, aes(x=Diagnosis, y=Value, fill=Diagnosis)) +
    geom_bar (position="dodge", stat = "identity",colour="black")+
    geom_errorbar(aes(ymin=Value, ymax=Value+se), colour="black", width=.1) +
    scale_fill_manual(values=c("#0000CC","#FF9900","#CC0000"),name="Diagnostic group")+ # Legend label, use darker colors
    facet_grid(Phase~FieldName, scales ='free') +
scale_x_discrete(breaks=NULL)+ 
    ylab("Parameter Estimate") +
    xlab("")+
    theme_bw() 

Change scale

g1 + 
scale_y_continuous(trans='log10',
    breaks = trans_breaks("log10", function(x) 10^x),
    labels = trans_format("log10", math_format(10^.x))
    ) 

Euler plot and Venn Chart

library(eulerr)
VennDiag <- euler(c("A" = 1.8, "B" = 1.5, "C" = 10.6, "A&B" = 0, "B&C" = 3.0, 
                    "A&C" = 1.1, "A&B&C" = 1.2))
p =plot(VennDiag, counts = TRUE, font=1, cex=1, alpha=0.5,
     fill=c("grey", "lightgrey", "darkgrey"))

Euler plot and Venn Chart

# get vector with color values
col = as.character(x$ColWithColourNames)
# add names to vector indicating value Factor values
names(col) = as.character(x$FactorA)
# plot
ggplot(x, aes(x = Chromosome, y = VAF, color = FactorA)) + scale_color_manual(values=col)