diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a956dbabede7692a5492f1e21491baa9a41f7030 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# DC_theme_generator : a theme generator for ggplot2 + + + +```ggplot2``` is a fantastic package made available by the great people over at [tidyverse](https://ggplot2.tidyverse.org/). ```ggplot2``` is great for designing plots layer by layer in R. Although ```ggplot2``` provides theming capabilities, the default choices available through the package can seem mundane and unapplealing for making publication quality figures. + +See these examples: + + + +I found myself writing these ```ggplot2::theme()``` objects everytime I wanted to plot something. So I wrote an R function that allows me to customize some key aspects of ```ggplot2::theme()``` and have a bit more granular control over the aesthetics of the "canvas" of my plots so to speak. + +```DC_theme_generator``` has handpicked defaults that make a plot look beautiful right out of the box. + +## Using DC_theme_generator + +```R +source("https://gitlab.utu.fi/deecha/ggplot_themes/-/raw/master/DC_theme_generator.R") + +customtheme <- DC_theme_generator(type='L') +ggplot()+geom_point()+customtheme +``` + +More detailed usage instructions along with an example can be found in the R script ```source.R``` in this repo. + +Here is an example tweaking some of the defaults: + +```R +source("https://gitlab.utu.fi/deecha/ggplot_themes/-/raw/master/DC_theme_generator.R") +customtheme <- DC_theme_generator(type = 'L', + legend = 'F', + ticks = 'out', + x.axis.angle = 45, + hjust = 0.5, + vjust = 0.5, + fontsize.cex = 1.8, + fontfamily = 'mono') + +ggplot(data = dat, aes(x=X, y=Y, color=Class)) + geom_point() + scale_color_manual(values=c("red","blue")) + xlab("X-axis") + ylab("Y-axis") + ggtitle("Customized DC_theme_generator") + customtheme +``` + diff --git a/img/animation.gif b/img/animation.gif new file mode 100644 index 0000000000000000000000000000000000000000..c9eb5bec873a04edfebddc8adddb49fc3197c0d1 Binary files /dev/null and b/img/animation.gif differ diff --git a/source.R b/source.R new file mode 100644 index 0000000000000000000000000000000000000000..ea683f0482a3efa2bda201025a77689e6278c6cb --- /dev/null +++ b/source.R @@ -0,0 +1,38 @@ +rm(list=ls()) +set.seed(100) +a <- rnorm(50,mean = 50,sd = 1) +b <- rnorm(50,mean = 0,sd = 1) +dat <- data.frame(X=a,Y=b) +dat$Class <- sample(x = c("beta","alpha"),size = 10,replace = T) + +library(ggplot2) + +ggplot(data = dat,aes(x=X,y=Y,color=Class))+geom_point()+scale_color_manual(values=c("red","blue"))+xlab("X-axis")+ylab("Y-axis")+ggtitle("Default theme") +ggsave("~/Desktop/tmp/1.png",width = 6,height = 5,dpi = "print") + +ggplot(data = dat,aes(x=X,y=Y,color=Class))+geom_point()+scale_color_manual(values=c("red","blue"))+xlab("X-axis")+ylab("Y-axis")+ggtitle("ggplot2::theme_bw")+theme_bw() +ggsave("~/Desktop/tmp/2.png",width = 6,height = 5,dpi = "print") + +source("https://gitlab.utu.fi/deecha/ggplot_themes/-/raw/master/DC_theme_generator.R") + +customtheme <- DC_theme_generator(type='L') +ggplot(data = dat,aes(x=X,y=Y,color=Class))+geom_point()+scale_color_manual(values=c("red","blue"))+xlab("X-axis")+ylab("Y-axis")+ggtitle("DC_theme_generator('L')")+customtheme +ggsave("~/Desktop/tmp/3.png",width = 6,height = 5,dpi = "print") + +customtheme <- DC_theme_generator(type='square') +ggplot(data = dat,aes(x=X,y=Y,color=Class))+geom_point()+scale_color_manual(values=c("red","blue"))+xlab("X-axis")+ylab("Y-axis")+ggtitle("DC_theme_generator('square')")+customtheme +ggsave("~/Desktop/tmp/4.png",width = 6,height = 5,dpi = "print") + + + + +customtheme <- DC_theme_generator(type = 'L', + legend = 'F', + ticks = 'in', + x.axis.angle = 45, + hjust = 0.5, + vjust = 0.5, + fontsize.cex = 1.8, + fontfamily = 'mono') + +ggplot(data = dat, aes(x=X,y=Y,color=Class)) + geom_point() + scale_color_manual(values=c("red","blue")) + xlab("X-axis") + ylab("Y-axis") + ggtitle("Customized DC_theme_generator") + customtheme