mirror of
https://github.com/dchakro/ggplot_themes.git
synced 2026-05-17 11:22:16 -07:00
Squashed commit of the following:
commit 6f817ea39cee879a6022c5debc3c22eceadbec02
Author: dchakro <35454738+dchakro@users.noreply.github.com>
Date: Tue Aug 25 16:05:09 2020 +0300
Updates
commit 7b789a0ea89c057e4bc3e205198b3374c7d3d312
Author: dchakro <35454738+dchakro@users.noreply.github.com>
Date: Tue Aug 25 16:02:58 2020 +0300
add support for font face.
bold, italic, bold-italic and plain.
This commit is contained in:
parent
a7cbcef0a4
commit
c9f0f67fe1
2 changed files with 43 additions and 23 deletions
|
|
@ -1,16 +1,15 @@
|
||||||
####
|
DC_theme_generator <- function(type, legend=T, ticks="out", x.axis.angle=0, hjust=0.5, vjust=0.5, fontsize.cex=1.5, fontfamily="serif", fontstyle="bold.italic"){
|
||||||
## Author: Deepankar Chakroborty
|
|
||||||
## Available at: https://gitlab.utu.fi/deecha/ggplot_themes/
|
# # Generate themes for ggplot2
|
||||||
## Report issues: https://gitlab.utu.fi/deecha/ggplot_themes/-/issues/new
|
# # Author: Deepankar Chakroborty
|
||||||
|
# # Available at: https://github.com/dchakro/ggplot_themes
|
||||||
|
# # Report issues: https://github.com/dchakro/ggplot_themes/issues
|
||||||
|
|
||||||
DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.5,vjust=0.5,fontsize.cex=1.5,fontfamily="serif"){
|
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
# type: 'L', 'square'
|
# type: 'L', 'square'
|
||||||
# ticks: 'in', 'out'
|
# ticks: 'in', 'out'
|
||||||
# fontfamily: 'serif' , 'sans' , 'mono'
|
# fontfamily: 'serif' , 'sans' , 'mono'
|
||||||
|
# fontstyle = 'plain', 'italic', 'bold', 'bold.italic'
|
||||||
|
|
||||||
ticks <- tolower(ticks)
|
ticks <- tolower(ticks)
|
||||||
fontfamily <- tolower(fontfamily)
|
fontfamily <- tolower(fontfamily)
|
||||||
|
|
@ -26,15 +25,20 @@ DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.
|
||||||
panel.background=element_blank(),
|
panel.background=element_blank(),
|
||||||
panel.grid.major=element_line(color=NA),
|
panel.grid.major=element_line(color=NA),
|
||||||
axis.ticks = element_line(colour = "black"),
|
axis.ticks = element_line(colour = "black"),
|
||||||
text = element_text(family = fontfamily),
|
text = element_text(family = fontfamily,
|
||||||
|
face = fontstyle),
|
||||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2),"cm"),
|
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2),"cm"),
|
||||||
axis.title = element_text(size=rel(fontsize.cex)),
|
axis.title = element_text(size=rel(fontsize.cex)),
|
||||||
axis.text.y = element_text(size = rel(fontsize.cex),
|
axis.text.y = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
size = rel(fontsize.cex),
|
||||||
hjust = 0.5,
|
hjust = 0.5,
|
||||||
angle = 0,
|
angle = 0,
|
||||||
color="black",
|
color="black",
|
||||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||||
axis.text.x = element_text(angle = x.axis.angle,
|
axis.text.x = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
angle = x.axis.angle,
|
||||||
hjust = hjust,
|
hjust = hjust,
|
||||||
vjust = vjust,
|
vjust = vjust,
|
||||||
size = rel(fontsize.cex),
|
size = rel(fontsize.cex),
|
||||||
|
|
@ -53,15 +57,20 @@ DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.
|
||||||
panel.background=element_blank(),
|
panel.background=element_blank(),
|
||||||
panel.grid.major=element_line(color=NA),
|
panel.grid.major=element_line(color=NA),
|
||||||
axis.ticks = element_line(colour = "black"),
|
axis.ticks = element_line(colour = "black"),
|
||||||
text = element_text(family = fontfamily),
|
text = element_text(family = fontfamily,
|
||||||
|
face = fontstyle),
|
||||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2),"cm"),
|
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2),"cm"),
|
||||||
axis.title = element_text(size=rel(fontsize.cex)),
|
axis.title = element_text(size=rel(fontsize.cex)),
|
||||||
axis.text.y = element_text(size = rel(fontsize.cex),
|
axis.text.y = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
size = rel(fontsize.cex),
|
||||||
hjust = 0.5,
|
hjust = 0.5,
|
||||||
angle = 0,
|
angle = 0,
|
||||||
color="black",
|
color="black",
|
||||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||||
axis.text.x = element_text(angle = x.axis.angle,
|
axis.text.x = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
angle = x.axis.angle,
|
||||||
hjust = hjust,
|
hjust = hjust,
|
||||||
vjust = vjust,
|
vjust = vjust,
|
||||||
size = rel(fontsize.cex),
|
size = rel(fontsize.cex),
|
||||||
|
|
@ -85,15 +94,20 @@ DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.
|
||||||
panel.grid.major = element_blank(),
|
panel.grid.major = element_blank(),
|
||||||
panel.grid.minor = element_blank(),
|
panel.grid.minor = element_blank(),
|
||||||
axis.ticks = element_line(colour = "black"),
|
axis.ticks = element_line(colour = "black"),
|
||||||
text = element_text(family = fontfamily),
|
text = element_text(family = fontfamily,
|
||||||
|
face = fontstyle),
|
||||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2), "cm"),
|
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2), "cm"),
|
||||||
axis.title = element_text(size=rel(fontsize.cex)),
|
axis.title = element_text(size=rel(fontsize.cex)),
|
||||||
axis.text.y = element_text(size = rel(fontsize.cex),
|
axis.text.y = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
size = rel(fontsize.cex),
|
||||||
hjust = 0.5,
|
hjust = 0.5,
|
||||||
angle = 0,
|
angle = 0,
|
||||||
color="black",
|
color="black",
|
||||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||||
axis.text.x = element_text(angle = x.axis.angle,
|
axis.text.x = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
angle = x.axis.angle,
|
||||||
hjust = hjust,
|
hjust = hjust,
|
||||||
vjust = vjust,
|
vjust = vjust,
|
||||||
size = rel(fontsize.cex),
|
size = rel(fontsize.cex),
|
||||||
|
|
@ -112,15 +126,20 @@ DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.
|
||||||
panel.grid.major = element_blank(),
|
panel.grid.major = element_blank(),
|
||||||
panel.grid.minor = element_blank(),
|
panel.grid.minor = element_blank(),
|
||||||
axis.ticks = element_line(colour = "black"),
|
axis.ticks = element_line(colour = "black"),
|
||||||
text = element_text(family = fontfamily),
|
text = element_text(family = fontfamily,
|
||||||
|
face = fontstyle),
|
||||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2), "cm"),
|
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2), "cm"),
|
||||||
axis.title = element_text(size=rel(fontsize.cex)),
|
axis.title = element_text(size=rel(fontsize.cex)),
|
||||||
axis.text.y = element_text(size = rel(fontsize.cex),
|
axis.text.y = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
size = rel(fontsize.cex),
|
||||||
hjust=0.5,
|
hjust=0.5,
|
||||||
angle=0,
|
angle=0,
|
||||||
color="black",
|
color="black",
|
||||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||||
axis.text.x = element_text(angle = x.axis.angle,
|
axis.text.x = element_text(family = fontfamily,
|
||||||
|
face = "plain",
|
||||||
|
angle = x.axis.angle,
|
||||||
hjust = hjust,
|
hjust = hjust,
|
||||||
vjust = vjust,
|
vjust = vjust,
|
||||||
size = rel(fontsize.cex),
|
size = rel(fontsize.cex),
|
||||||
|
|
@ -133,4 +152,4 @@ DC_theme_generator <- function(type,legend=T,ticks="out",x.axis.angle=0,hjust=0.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(themeToReturn)
|
return(themeToReturn)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
source.R
5
source.R
|
|
@ -13,7 +13,7 @@ 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()
|
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")
|
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")
|
source('https://raw.githubusercontent.com/dchakro/ggplot_themes/master/DC_theme_generator.R')
|
||||||
|
|
||||||
customtheme <- DC_theme_generator(type='L')
|
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
|
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
|
||||||
|
|
@ -33,6 +33,7 @@ customtheme <- DC_theme_generator(type = 'L',
|
||||||
hjust = 0.5,
|
hjust = 0.5,
|
||||||
vjust = 0.5,
|
vjust = 0.5,
|
||||||
fontsize.cex = 1.8,
|
fontsize.cex = 1.8,
|
||||||
fontfamily = 'mono')
|
fontfamily = 'mono',
|
||||||
|
fontstyle = "bold")
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue