Skip to content

X Y scatterplot_28016743

Rob Ness edited this page Jul 3, 2024 · 1 revision

title: "TheNessLab : X-Y scatterplot"

Created by Robert Ness, last modified on Jul 04, 2018

df

# import libraries
    library(ggplot2)
    library(scales)
    library(extrafont)

scientific_10 <- function(x) {
      parse(text=gsub("e+", "%*%10^", perl=TRUE,         scientific_format()(x)))
    }

df <- read.table('model_fit_histo.w_sitegens.txt', header=TRUE)
    fit <- lm(mutationrate ~ Mutability, data=df, weights=SiteGens)
    r2 <- as.character(as.expression(substitute(italic(R)^2==r2, list(r2 = format(summary(fit)$r.squared, digits = 3)))))
    my_font='Helvetica'
    pdf("weighted_regression_fit.pdf", family="Helvetica", width=10, height=8)
    ggplot(data = df, aes(x=Mutability,y=mutationrate)) +
        geom_smooth(data=df, method = "lm", formula = y ~ x, aes(weight=sites), colour = "red", alpha=0.1) +
        geom_point(data=df, aes(x=Mutability,y=mutationrate,size=sites), shape=16, colour="#003399") +
        annotate(geom = "text", label=r2, x=0.05, y=1e-8, parse=TRUE, size=12) +
        labs(y="Obs. mutation rate", x="Predicted mutability") +
        scale_y_continuous(label = scientific_10) +
        scale_size_continuous(name="# of sites", breaks=c(1e+06,5e+06,10e+06), label = scientific_10) +
        scale_size(name="# of sites", breaks=c(1e+06,5e+06,10e+06), label = scientific_10, range = c(4, 10)) +
        theme_bw() +
        theme(panel.border=element_blank(), axis.line = element_line(),panel.grid.minor=element_line(),
              legend.text = element_text(size = 18, family=my_font), legend.title=element_text(size = 18, family=my_font),
              legend.position=c(0.8,0.2),
              axis.text.x=element_text(size=20, family=my_font), axis.title.x=element_text(size=30, family=my_font,vjust=0.01),
              axis.text.y=element_text(size=20, family=my_font), axis.title.y=element_text(size=30, family=my_font,vjust=0.3)
             )

dev.off()

Document generated by Confluence on May 22, 2024 11:44

  • Chlamy Tips

  • Coding Tips.

  • HpcnodeLife.

  • Other Awesome Pages.

Clone this wiki locally