mirror of
https://github.com/dchakro/ggplot_themes.git
synced 2026-05-17 11:22:16 -07:00
Reduce complexity and add support for system fonts
This commit is contained in:
parent
3a22985ed4
commit
138478394c
1 changed files with 8 additions and 85 deletions
|
|
@ -8,15 +8,15 @@ DC_theme_generator <- function(type, legend=T, ticks="out", x.axis.angle=0, hjus
|
|||
## Options:
|
||||
# type: 'L', 'square'
|
||||
# ticks: 'in', 'out'
|
||||
# fontfamily: 'serif' , 'sans' , 'mono'
|
||||
# fontfamily: 'serif' , 'sans' , 'mono', 'Helvetica', 'Palatino'
|
||||
# ax.fontstyle = 'plain', 'italic', 'bold', 'bold.italic'
|
||||
|
||||
ticks <- tolower(ticks)
|
||||
fontfamily <- tolower(fontfamily)
|
||||
# Supports system fonts, and doesn't transform them to lower case as font names are case-sensitive.
|
||||
fontfamily <- ifelse(test = tolower(fontfamily) %in% c("sans","serif","mono"),yes = tolower(fontfamily),no = fontfamily)
|
||||
|
||||
if( type == "square"){
|
||||
if( legend ){
|
||||
# Type: square , with legend"
|
||||
# Type: square
|
||||
themeToReturn <- ggplot2::theme(
|
||||
panel.border = element_rect(linetype = 1,
|
||||
colour = "black",
|
||||
|
|
@ -49,53 +49,14 @@ DC_theme_generator <- function(type, legend=T, ticks="out", x.axis.angle=0, hjus
|
|||
size = rel(fontsize.cex),
|
||||
color = "black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
legend.key= element_rect(fill=NA,
|
||||
colour = NA)
|
||||
)
|
||||
}else{
|
||||
# Type: square , without legend"
|
||||
themeToReturn <- ggplot2::theme(
|
||||
panel.border = element_rect(linetype = 1,
|
||||
colour = "black",
|
||||
fill=NA,
|
||||
size=1),
|
||||
panel.background=element_blank(),
|
||||
panel.grid.major=element_line(color=NA),
|
||||
axis.ticks = element_line(colour = "black"),
|
||||
text = element_text(family = fontfamily),
|
||||
plot.title = element_text(family = fontfamily,
|
||||
face="bold",
|
||||
color = "black",
|
||||
size = rel(fontsize.cex)),
|
||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2),"cm"),
|
||||
axis.title = element_text(family = fontfamily,
|
||||
face = ax.fontstyle,
|
||||
size=rel(fontsize.cex)),
|
||||
axis.text.y = element_text(family = fontfamily,
|
||||
face = "plain",
|
||||
size = rel(fontsize.cex),
|
||||
hjust = 0.5,
|
||||
angle = 0,
|
||||
color="black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
axis.text.x = element_text(family = fontfamily,
|
||||
face = "plain",
|
||||
angle = x.axis.angle,
|
||||
hjust = hjust,
|
||||
vjust = vjust,
|
||||
size = rel(fontsize.cex),
|
||||
color = "black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
legend.key= element_rect(fill=NA,
|
||||
colour = NA),
|
||||
legend.position="none"
|
||||
legend.position=ifelse(test = legend,yes = "right" ,no = "none")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if( type == 'L' ){
|
||||
if( legend ){
|
||||
# Type: L , with legend"
|
||||
# Type: L
|
||||
themeToReturn <- ggplot2::theme(
|
||||
axis.line = element_line(colour = "black",
|
||||
size=0.5),
|
||||
|
|
@ -128,48 +89,10 @@ DC_theme_generator <- function(type, legend=T, ticks="out", x.axis.angle=0, hjus
|
|||
size = rel(fontsize.cex),
|
||||
color = "black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
legend.key = element_rect(fill=NA,
|
||||
colour = NA)
|
||||
)
|
||||
} else {
|
||||
# Type: L , without legend
|
||||
themeToReturn <- ggplot2::theme(
|
||||
axis.line = element_line(colour = "black",
|
||||
size=0.5),
|
||||
panel.border = element_blank(),
|
||||
panel.background = element_blank(),
|
||||
panel.grid.major = element_blank(),
|
||||
panel.grid.minor = element_blank(),
|
||||
axis.ticks = element_line(colour = "black"),
|
||||
text = element_text(family = fontfamily),
|
||||
plot.title = element_text(family = fontfamily,
|
||||
face="bold",
|
||||
color = "black",
|
||||
size = rel(fontsize.cex)),
|
||||
axis.ticks.length = unit(ifelse(ticks=="in",-0.2,0.2), "cm"),
|
||||
axis.title = element_text(family = fontfamily,
|
||||
face = ax.fontstyle,
|
||||
size=rel(fontsize.cex)),
|
||||
axis.text.y = element_text(family = fontfamily,
|
||||
face = "plain",
|
||||
size = rel(fontsize.cex),
|
||||
hjust = 0.5,
|
||||
angle = 0,
|
||||
color = "black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
axis.text.x = element_text(family = fontfamily,
|
||||
face = "plain",
|
||||
angle = x.axis.angle,
|
||||
hjust = hjust,
|
||||
vjust = vjust,
|
||||
size = rel(fontsize.cex),
|
||||
color = "black",
|
||||
margin=unit(c(0.3,0.3,0.3,0.3), "cm")),
|
||||
legend.key = element_rect(fill=NA,
|
||||
colour = NA),
|
||||
legend.position="none"
|
||||
legend.position=ifelse(test = legend,yes = "right" ,no = "none")
|
||||
)
|
||||
}
|
||||
}
|
||||
return(themeToReturn)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue